Last active
December 12, 2024 22:46
-
-
Save bokner/3614d3a1374af4508e0ada51d9571bbb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
include "globals.mzn"; | |
include "gecode.mzn"; | |
% | |
% Data | |
% | |
int: N; % number of nodes | |
set of int: NODE = 1..N; | |
array[NODE, NODE] of int: distances; % distance matrix | |
int: min_val = min([distances[i,j] | i,j in NODE where distances[i,j] > 0]); | |
int: max_val = max([distances[i,j] | i,j in NODE]); | |
array[NODE] of var min_val..max_val: d; | |
var min_val..sum(distances): distance; | |
constraint distance = sum(d); | |
array[NODE] of var NODE: route; % the circuit | |
constraint forall(i in NODE) ( | |
distances[i, route[i]] = d[i] | |
); | |
constraint circuit(route); | |
constraint value_precede(N, N-1, route); | |
%% Search | |
annotation relax_and_reconstruct(array[int] of var int,int); | |
annotation restart_luby(int); | |
solve | |
:: relax_and_reconstruct(d ++ | |
route, 93) | |
:: restart_luby(100) | |
minimize distance; | |
output [ | |
show(distance) | |
]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment