[eclipse-clp-users] Order of constraints

From: Edgaonkar, Shrirang <Shrirang.Edgaonkar_at_nttdata.com>
Date: Fri, 27 Feb 2015 04:48:16 +0000
Dear Clp users,



  I am trying the following.



:- lib(ic).
solve(Nr, Hosts):-

Nr #> 6,
problem(Nr, Hosts),

writeln(end).

problem(Nr, Hosts):-

        findall(boat{nr:Nr,cap:Cap,crew:Crew,sorting:Space},
                (boat(Nr,Cap,Crew)),Hosts).

boat(1 , 6 , 2).
boat(2 , 8 , 2).
boat(3 , 12 , 2).
boat(4 , 12 , 2).
boat(5 , 12 , 4).
boat(6 , 12 , 4).
boat(7 , 12 , 4).
boat(8 , 10 , 1).
boat(9 , 10 , 2).



The output is following which is right:-

?- solve(Nr, Hosts).
Nr = Nr{7 .. 1.0Inf}
Hosts = [boat{nr : 7, cap : 12, crew : 4, sorting : _515}, boat{nr : 8, cap : 10, crew : 1, sorting : _540}, boat{nr : 9, cap : 10, crew : 2, sorting : _565}]
Yes (0.02s cpu)

------------------------------------------------------------------------------------------------------------

Now I change the script where I change the order of constraints in solve.

:- lib(ic).
solve(Nr, Hosts):-

problem(Nr, Hosts),
Nr #> 6,

writeln(end).

problem(Nr, Hosts):-

        findall(boat{nr:Nr,cap:Cap,crew:Crew,sorting:Space},
                (boat(Nr,Cap,Crew)),Hosts).

boat(1 , 6 , 2).
boat(2 , 8 , 2).
boat(3 , 12 , 2).
boat(4 , 12 , 2).
boat(5 , 12 , 4).
boat(6 , 12 , 4).
boat(7 , 12 , 4).
boat(8 , 10 , 1).
boat(9 , 10 , 2).



Now the output is the following:-

?- solve(Nr, Hosts).
Nr = Nr{7 .. 1.0Inf}
Hosts = [boat{nr : 1, cap : 6, crew : 2, sorting : _478}, boat{nr : 2, cap : 8, crew : 2, sorting : _503}, boat{nr : 3, cap : 12, crew : 2, sorting : _528}, boat{nr : 4, cap : 12, crew : 2, sorting : _553}, boat{nr : 5, cap : 12, crew : 4, sorting : _578}, boat{nr : 6, cap : 12, crew : 4, sorting : _603}, boat{nr : 7, cap : 12, crew : 4, sorting : _628}, boat{nr : 8, cap : 10, crew : 1, sorting : _653}, boat{nr : 9, cap : 10, crew : 2, sorting : _678}]
Yes (0.00s cpu)



My problem is I cannot control the sequence in which constrants appear in my script as it is autogenerated. Is there any other way to handle this.

One way is the following:-

:- lib(ic).
solve(Nr, Hosts):-

problem(Nr, Hosts),

writeln(end).

problem(Nr, Hosts):-

        findall(boat{nr:Nr,cap:Cap,crew:Crew,sorting:Space},
                (boat(Nr,Cap,Crew),Nr #> 6),Hosts).

boat(1 , 6 , 2).
boat(2 , 8 , 2).
boat(3 , 12 , 2).
boat(4 , 12 , 2).
boat(5 , 12 , 4).
boat(6 , 12 , 4).
boat(7 , 12 , 4).
boat(8 , 10 , 1).
boat(9 , 10 , 2).



But it wont work for me. I will the constraint Nr #> 6 only in solve. Please help.



Thanks and Regards,

Shrirang Edgaonkar

______________________________________________________________________
Disclaimer: This email and any attachments are sent in strictest confidence
for the sole use of the addressee and may contain legally privileged,
confidential, and proprietary data. If you are not the intended recipient,
please advise the sender by replying promptly to this email and then delete
and destroy this email and any attachments without any further use, copying
or forwarding.
Received on Fri Feb 27 2015 - 04:49:55 CET

This archive was generated by hypermail 2.2.0 : Fri Feb 27 2015 - 21:15:25 CET