Clingo constraint not working properly and being ignored

I have a Clingo program optimising parcel delivery, and there are 2 constraints to limit the weight and the volume a car can deliver respectively, however these constraints are not working.

weightLimit(500).
volumeLimit(1000).

cars(2).

parcel(1,a,1,400).
parcel(2,b,1,400).
parcel(3,c,1,400).

%Constraint volume
:- #sum {V, X, Y, T: assign(X, Y), parcel(X,_,T,_), parcelType(T,V)} > volumeLimit.

%Constraint weight limit
:- #sum {W, X, Y:  assign(X, Y), parcel(X,_,_,W)} > weightLimit.

This should be unsatisfiable because it is impossible to deliver all those parcels with only 2 cars since the weight limit is only 500, but when I run it, it just assigns parcels over the weight limit.

  • You should clarify how you are interpreting each predicate.

    – 

  • Regarding the weight, the parcel predicate can be seen as parcel(id,region,type,weight), the type is related to the volume (referenced later). Every car has the same weight and volume limit as stated in the first 2 lines and I wanted to constraint the weight so that it was impossible for a car to be assigned to parcels that have a sum of weight greater than the car’s weight limit. However the constraint I wrote is not working properly since it assigns 2 parcels to one car in the example. The volume works in a similar way, but to get the value we use the predicate parcelType(type, volume).

    – 

  • Your program is incomplete. Please add also the assign/2 and parcelType/2 atoms

    – 

Leave a Comment