# Help Needed

From: <albinali_at_email.arizona.edu>
Date: Fri 09 May 2003 03:07:22 PM GMT
Message-ID: <3EBBA2F6000001E4@phobos.email.Arizona.EDU>
```Hi everyone,
I am new to the list. I have been trying to write some code in ECLiPSe
with no much success. I am having a problem with comparing some list values.
I have pasted down my code and I have marked the area where I need some help.

Fahd
University of Arizona

:-lib(fd).
:-lib(listut).

solve(Vars, Time):-

N = 8,

length(Vars, N),
Vars::1..N,
alldifferent(Vars),
last(ALast, Vars),
ALast = 1,

vars_cost(Vars, AVar, Minor, Major),

length(TVar, N),
last(TLast, Time),

var_assignment(Vars, Costs),

compute_costs(TVar, Costs, AVar, Minor, Major),

Tot #= TLast,
minimize(labeling(Arcs), Tot).

vars_cost([], [], [], []).
vars_cost([Arc|Vars], [Cost|Costs], [Mi|Mj], [Ui|Uj]):-
element(Arc, [0, 10, 5, 12, 7, 1, 8, 9], Cost),
element(Arc, [10, 0, 10, 10, 10, 10, 10, 10], Li),
element(Arc, [100, 100, 100, 100, 100, 100, 100, 100], Ui),
vars_cost(Vars, Costs, Mj, Uj).

var_assignment(Vars, Cost):-

Vars = [V1, V2, V3, V4, V5, V6, V7, V8],
Cost = [C1, C2, C3, C4, C5, C6, C7, C8],

Matrix = m(r(0,0,2,5,10,5,6,6),
r(9,9,0,3,8,3,4,4),
r(6,6,3,0,5,0,1,1),
r(5,5,7,10,0,13,11,11),
r(0,0,2,5,10,5,6,6),
r(5,5,2,5,10,5,0,0),
r(9,9,0,3,8,3,4,4),
r(0,0,2,5,10,5,6,6)),

wait_for([1, V1], subscript(Matrix, [1,V1], C1)),
wait_for([V1, V2], subscript(Matrix, [V1,V2], C2)),
wait_for([V2, V3], subscript(Matrix, [V2,V3], C3)),
wait_for([V3, V4], subscript(Matrix, [V3,V4], C4)),
wait_for([V4, V5], subscript(Matrix, [V4,V5], C5)),
wait_for([V5, V6], subscript(Matrix, [V5,V6], C6)),
wait_for([V6, V7], subscript(Matrix, [V6,V7], C7)),
wait_for([V7, V8], subscript(Matrix, [V7,V8], C8)).

compute_costs([], [], [], [], []).
compute_costs([Ti|TRj], [Ci|Cj], [ACi|ACj], [Mi|Mj],[Ui|Uj]):-
Ti #>= Li,
Ti #<= Ui,
Ci + ACi #= Ti,
compute_rest_cost([Ti|TRj],Cj,ACj,Lj,Uj).

compute_rest_cost([_],[],[],[],[]).
compute_rest_cost([Ti,Tj|TRj],[Ci|Cj],[ACj|ACs],[Lj|Ls], [Uj|Us]):-
Tj #>= Lj,
Tj #<= Uj,
Ti + Ci + ACj #= Tj,
%%%%%%%%%%%%%%%%%%%%%%
%		what I need over here is the following:
%		If Acj + Lj is greater than Tj then
%			I would like to assign Acj +Lj to Tj
%		otherwise
%			do nothing
%
%		I have been trying to do that for some time with no success
%		Shedding some light on this issue will be highly appreciated. Thanks.
%
%%%%%%%%%%%%%%%%%%%%%%
compute_rest_cost([Tj|TRj],Cj,ACs,Ls,Us).

wait_for([], Goal):-
call(Goal).
wait_for([X|Xs], Goal):-
(var(X) ->
suspend(wait_for(Xs, Goal), 2, [X -> inst])
;
wait_for(Xs, Goal)
).
```
Received on Fri May 09 18:08:07 2003

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