Beginner to ASP here :) I need to define a default value for an atom when it isn't provided in the input.
% creating rooms
cost(create(room(R)), W) :- room(R), roomDomainNew(R), roomCost(W).
Here, if roomCost(W)
is not defined, I want to fallback to a roomCost(0)
zero cost. How do I do this?
Defining a roomCost(0)
when the input has a roomCost
of its own, leads to both co-existing.
roomCost(0).
roomCost(5).
In other languages, I could do something like:
finalRoomCost = 0
if roomCost:
finalRoomCost = roomCost
and then I could use finalRoomCost
. Is that possible here?
Related answer here, which says such mutability is not possible.
In ASP truth values do not change over time, either atoms are
true
orfalse
for a specific answer set, they can not be overwritten.
So here's the solution I went with, using a #max
directive:
roomCost(0).
finalroomCost(W) :- roomCost(0), #max {X, 1 : roomCost(X)} = W.