Skip to content

Instantly share code, notes, and snippets.

@bokner
Created December 21, 2024 02:48
Show Gist options
  • Select an option

  • Save bokner/e3d5d73991b3c40ce89663df911e26fe to your computer and use it in GitHub Desktop.

Select an option

Save bokner/e3d5d73991b3c40ce89663df911e26fe to your computer and use it in GitHub Desktop.
include "globals.mzn";
int: N;
set of int: LOCATION = 1..N;
array[LOCATION, LOCATION] of int: flow;
array[LOCATION, LOCATION] of int: distances;
array[LOCATION] of var LOCATION: location_assignments;
constraint alldifferent(location_assignments);
solve
:: int_search(location_assignments,
dom_w_deg, indomain_min)
:: relax_and_reconstruct(location_assignments, 65)
:: restart_luby(500)
minimize
sum(i in LOCATION, j in LOCATION)(
flow[i,j] * distances[location_assignments[i], location_assignments[j]]
);
output ["facility \(i) => \(location_assignments[i])\n" | i in LOCATION] ++
["total cost = \(_objective)\n" ];
@bokner
Copy link
Author

bokner commented Dec 21, 2024

% Solution (Gecode)
%
facility 1 => 11
facility 2 => 26
facility 3 => 15
facility 4 => 7
facility 5 => 4
facility 6 => 13
facility 7 => 12
facility 8 => 6
facility 9 => 2
facility 10 => 18
facility 11 => 9
facility 12 => 1
facility 13 => 5
facility 14 => 21
facility 15 => 8
facility 16 => 14
facility 17 => 3
facility 18 => 19
facility 19 => 20
facility 20 => 10
facility 21 => 25
facility 22 => 17
facility 23 => 24
facility 24 => 16
facility 25 => 23
facility 26 => 22
total cost = 5426670
% time elapsed: 1m 26s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment