Prolog-Graphplan icon indicating copy to clipboard operation
Prolog-Graphplan copied to clipboard

Read current state inside adds

Open illbexyz opened this issue 8 years ago • 2 comments

Hello, I'd like to solve a variant of your Rocket problem where:

  • the rockets have a quantifiable amount of fuel (e.g. 1000 units)
  • moving from a city to another one consumes some amount of fuel (e.g. 300 units).

In order to solve this, I thought I might add to the state a predicate: fuel(Rocket, FuelAmount).

But how can I update the state inside the adds predicate? I mean, can I somehow access the current state to read the FuelAmount of a Rocket in order to add fuel(Rocket, RemainingFuel) where RemainingFuel is FuelAmount - 300?

I'm sorry to trouble you but i'm unexperienced in Prolog and I can't tell if there's an obvious way solve this or if it's a limitation of Graphplan.

illbexyz avatar Aug 08 '17 17:08 illbexyz

ok, I haven't done prolog in a very long while, but I think that you want something like:

distance(From, To, 300).

can(move(Rocket,From,To, FuelAmount),[at(Rocket,From), has_fuel(Rocket, FuelAmount)], rocket) :- 
	rocket(Rocket),
	place(From),
	place(To),
        distance(From, To, X),
        FuelAmount > X,
	From \= To.

adds(move(Rocket,_From,To, OldFA),[at(Rocket, To), has_fuel(Rocket, NewFuelAmount)], at(Rocket,To), rocket):-
	rocket(Rocket),
        distance(From, To, X),
        NewFuelAmount is OldFA - X,
	place(To).

deletes(move(Rocket,From,_To, OldFA),[at(Rocket,From), has_fuel(Rocket, OldFA)], rocket):-
	rocket(Rocket),
	place(From).

I haven't tested it, but it's probably the way to start looking at this.

Mortimerp9 avatar Aug 08 '17 21:08 Mortimerp9

Thank you!

This solution doesn't seem to work unless I define a fuelAmountpredicate as a world fact listing all the possible values for the fuel.

But this is not what i'm trying to accomplish because i'd like move to be called only with the values of fuel inside the state.

illbexyz avatar Aug 09 '17 10:08 illbexyz