Download
# Licenced under CC-BY-4.0 : http://creativecommons.org/licenses/by/4.0/
MAIN MODEL Main_AllInterval
DECLARATION SECTION
MATHEMATICAL PROGRAM:
identifier : AllIntervalPlan
direction : minimize
constraints : AllConstraints
variables : AllVariables
type : CSP ;
PARAMETER:
identifier : N
initial data : 12 ;
PARAMETER:
identifier : N1
definition : N-1 ;
SET:
identifier : i1
subset of : Integers
index : i
definition : {1..N} ;
SET:
identifier : j1
subset of : Integers
indices : j, k
definition : {1..N1} ;
VARIABLE:
identifier : x
index domain : (i)
range : {1..N} ;
VARIABLE:
identifier : diffs
index domain : k
range : {1..N1} ;
CONSTRAINT:
identifier : AllDiffDiffs
definition : cp::AllDifferent(j, diffs(j)) ;
CONSTRAINT:
identifier : AllDiffX
definition : cp::AllDifferent(i, x(i)) ;
CONSTRAINT:
identifier : DiffsK
index domain : i | i <> last( i1 )
definition : diffs(i) = Abs(x(i)-x(i+1))
comment : "Note the special handling of the index domain for this constraint." ;
CONSTRAINT:
identifier : Symm1
definition : x(1) < x(n-1) ;
CONSTRAINT:
identifier : Symm2
definition : diffs(1) < diffs(2) ;
ENDSECTION ;
PROCEDURE
identifier : MainInitialization
ENDPROCEDURE ;
PROCEDURE
identifier : MainExecution
body :
ShowProgressWindow ;
solve AllIntervalPlan;
if (AllIntervalPlan.ProgramStatus <> 'Optimal') then
/* empty x, diffs; */
endif;
DialogMessage(GMP::Solution::Count('AllIntervalPlan') + " solutions");
ENDPROCEDURE ;
PROCEDURE
identifier : MainTermination
body :
return DataManagementExit();
ENDPROCEDURE ;
ENDMODEL Main_AllInterval ;