documentation and small fixes; also call for foreach

This commit is contained in:
Vítor Santos Costa
2013-09-29 11:31:18 +01:00
parent bef9cec46a
commit 7cf1b68c3a
7 changed files with 560 additions and 119 deletions

View File

@@ -48,7 +48,7 @@ problem(Z, X, InFlow, OutFlow, N) :-
% constraint
for(I in 1..N,
foreach(I in 1..N,
( I == Start ->
RHS[I] <== 1 ;
I == End ->
@@ -58,21 +58,21 @@ problem(Z, X, InFlow, OutFlow, N) :-
% must be larger than 0??
for( [I in 1..N, J in 1..N],
foreach( [I in 1..N, J in 1..N],
( D[J,I] = M ->
X[J,I] #= 0 ;
true )
),
% outflow constraint
for(I in 1..N,
foreach(I in 1..N,
OutFlow[I] #= sum(J in 1..N where D[J,I]<M, X[J,I])
),
% inflow constraint
for(J in 1..N,
foreach(J in 1..N,
InFlow[J] #= sum(I in 1..N where D[J,I]<M, X[J,I])
),
% inflow = outflow
for(I in 1..N, OutFlow[I]-InFlow[I]#=RHS[I]),
foreach(I in 1..N, OutFlow[I]-InFlow[I]#=RHS[I]),
% labeling
labeling( [], X).
@@ -118,7 +118,7 @@ out(Cost, Ts, Ins, Out, N) :-
format('Inputs =', []), maplist(out, InsL), nl,
format('Outputs =', []), maplist(out, OutL), nl,
format('transitions =~n', []),
for(I in 1..N, outl(Ts[_,I]) ).
foreach(I in 1..N, outl(Ts[_,I]) ).
outl( X ) :-
L <== X, % evaluate matrix notation to Prolog lists.

View File

@@ -18,11 +18,11 @@ problem(Ex, Els) :- ex(Ex, Exs),
Els ins 1..9,
M <== matrix( Els, [dim=[9,9]] ),
% select rows
for( I in 0..8 , all_different(M[I,*]) ),
foreach( I in 0..8 , all_different(M[I,*]) ),
% select cols
for( J in 0..8, all_different(M[*,J]) ),
foreach( J in 0..8, all_different(M[*,J]) ),
% select squares
for( [I,J] ins 0..2 ,
foreach( [I,J] ins 0..2 ,
all_different(M[I*3+(0..2),J*3+(0..2)]) ),
ex(Ex, Exs),
maplist( bound, Els, Exs),
@@ -39,12 +39,12 @@ bound(El, X) :-
%
output(Els) :-
M <== matrix( Els, [dim=[9,9]] ),
for( I in 0..2 , output(M, I) ),
foreach( I in 0..2 , output(M, I) ),
output_line.
output(M, I) :-
output_line,
for( J in 0..2 , output_row(M, J+I*3) ).
foreach( J in 0..2 , output_row(M, J+I*3) ).
output_row( M, Row ) :-
L <== M[Row,_],