Re: Complex problem ?

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Thu 05 Jul 2001 04:17:32 PM GMT
Message-ID: <3B44931C.9142DD9A@icparc.ic.ac.uk>
Manuel Weindorf wrote:
> 
> Hi there,
> 
> up to now I used Eclipse as a Prolog system, but now I guess I have a
> 'real' CSP, but I don't know how to set it up :-(

This is actually simple enough to solve without constraint
propagation. ECLiPSe program follows (just add your facts):


:- lib(branch_and_bound).

best(Triplets) :-
	bb_min(solve(Triplets, Cost), Cost, _).

solve(Triplets, Cost) :-
	findall(R, ball(R, red), RedIds),
	findall(B, ball(B, blue), BlueIds),
	findall(G, ball(G, green), GreenIds),

	NTriples is min(length(RedIds),
			min(length(BlueIds), length(GreenIds))),
	(
	    for(_,1,NTriples),
	    foreach(triplet(Red,Blue,Green), Triplets),
	    fromto(RedIds, RedIds1, RedIds2, _),
	    fromto(BlueIds, BlueIds1, BlueIds2, _),
	    fromto(GreenIds, GreenIds1, GreenIds2, _),
	    fromto(0, Cost1, Cost2, Cost)
	do
	    delete(Red, RedIds1, RedIds2),
	    delete(Blue, BlueIds1, BlueIds2),
	    delete(Green, GreenIds1, GreenIds2),
	    Cost2 is Cost1 + cost(Red,Blue)
			+ cost(Red,Green) + cost(Blue,Green)
	).


-- 
 Joachim Schimpf              /             phone: +44 20 7594 8187
 IC-Parc, Imperial College   /            mailto:J.Schimpf@ic.ac.uk
 London SW7 2AZ, UK         /    http://www.icparc.ic.ac.uk/eclipse
Received on Thu Jul 05 17:17:44 2001

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:09 PM GMT GMT