Created
March 13, 2015 08:13
-
-
Save kim0/ba480a0f918c41e1a2e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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