Last active
December 21, 2024 18:29
-
-
Save bokner/bf5a88f40b7ed990fee7a97880d12f07 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"; | |
int: N; | |
set of int: NODES = 1..N; | |
int: E; | |
set of int: EDGES = 1..E; | |
int: M; | |
set of int: MANDATORY = 1..M; | |
array[EDGES] of int: from; | |
array[EDGES] of int: to; | |
array[EDGES] of int: weight; | |
array[MANDATORY] of int: mandatory; | |
array[NODES] of var bool: node_included; | |
array[EDGES] of var bool: edge_included; | |
var min(weight)..sum(weight): total_weight; | |
constraint forall(m in MANDATORY)( | |
node_included[mandatory[m]] = true | |
); | |
constraint steiner(N, E, from, to, weight, node_included, edge_included, | |
total_weight); | |
solve minimize total_weight; | |
output [if fix(edge_included[e]) then "\(from[e]) -> \(to[e])\n" else "" endif | e in EDGES] ++ ["\ntotal_cost: \(_objective)"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
% Solution (Chuffed)
7 -> 29
18 -> 28
18 -> 43
20 -> 7
20 -> 27
20 -> 48
21 -> 12
22 -> 20
22 -> 21
22 -> 43
27 -> 34
28 -> 24
29 -> 33
33 -> 35
36 -> 49
41 -> 22
41 -> 36
41 -> 47
47 -> 37
total_cost: 82
% time elapsed: 168msec
==========