paniz alipour wrote: > Hi to all > bin_packing(Bins, Weights, Capacity) :- > dim(Bins,[N]), > dim(Weights,[N]), > (for(B,1,N), > param(Weights,Bins,N,Capacity) do > (for(J,1,N), > fromto(0,In,Out,Sum), > param(Weights,Bins,B) do > > Bins[J] #= B > -> > Out #= In + Weights[J] > ; > Out = In > ), > Sum #=< Capacity > ). ... > > this is the bin packing problem ,I have a question about bin_packing > part , about Bin[j]#=B > this is for what This seems to be cut from http://www.hakank.org/eclipse/bin_packing2.ecl one of the models from Hakan Kjellerstrand's great ECLiPSe web page at http://www.hakank.org/eclipse/ The intention of this code is to set up the capacity constraint for a bin, by adding up the weigths of all objects J that are being put into bin B - that's what Bins[J] #= B means. This code is actually wrong, because you cannot use a constraint inside the condition of an if-then-else. The other variants of the predicate that Hakan gives in the file are fine - I recommend the last one: bin_packing4(Bins, Weights, Capacity) :- dim(Bins,[N]), dim(Weights,[N]), ( for(B,1,N), param(Weights,Bins,N,Capacity) do (for(J,1,N), foreach(S,Sum), param(Weights,Bins,B) do S = Weights[J]*(Bins[J] #= B) ), sum(Sum) #=< Capacity ). Here, (Bins[J] #= B) evaluates to 1 if J is in bin B, and 0 otherwise, so weight[J] gets added only if J is in the bin. -- JoachimReceived on Thu Jul 29 2010 - 03:37:40 CEST
This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET