Skip to content

Instantly share code, notes, and snippets.

@kim0
Created March 13, 2015 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kim0/ba480a0f918c41e1a2e9 to your computer and use it in GitHub Desktop.
Save kim0/ba480a0f918c41e1a2e9 to your computer and use it in GitHub Desktop.
% Simple Travelling Salesman problem
include "globals.mzn";
int: n; % number of cities
array[1..n,1..2] of float: l; % location (coords of citis)
n = 5;
l = [| 0.0, 0.0,
| 0.0, 0.5,
| 0.0, 1.0,
| 1.0, 1.0,
| 1.0, 0.0,
|];
array[1..n] of var 1..n: c; % cities visited in order. c[1] = first, c[2] = second
constraint c[1] = 1;
%constraint circuit(c);
constraint alldifferent(c);
% Minimize the euclidean distance between every point and the next, plus the last and first points
solve minimize(sum(i in 1..n-1)(sqrt( pow(l[c[i+1],1] - l[c[i],1],2) + pow(l[c[i+1],2] - l[c[i],2], 2) ) ) + sqrt( pow(l[c[1],1]-l[c[n],1], 2) + pow(l[c[1],2]-l[c[n],2], 2) ));
% $ mzn-gecode -a solver-sa.mzn
% Error: Registry: Constraint array_float_element not found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment