Skip to content

Instantly share code, notes, and snippets.

@liori
Last active December 20, 2015 07:39
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 liori/6095005 to your computer and use it in GitHub Desktop.
Save liori/6095005 to your computer and use it in GitHub Desktop.
Example set-cover implementation in GNU MathProg. Pick the minimal set of sentences which contain all the characters. Run with `glpsol --math setcover.mod --output /dev/fd/0`
set Sentences;
set Characters;
param contains{s in Sentences, c in Characters};
var chosen{s in Sentences} binary;
minimize size: sum{s in Sentences} chosen[s];
s.t. all_characters_covered{c in Characters}: sum{s in Sentences} contains[s, c] * chosen[s] >= 1;
data;
set Sentences := 1 2 3 4 5;
set Characters := 1 2 3 4 5 6 7 8 9;
param contains default 0
: 1 2 3 4 5 6 7 8 9 :=
1 1 1 1 0 0 0 0 0 0
2 0 0 1 1 0 1 0 1 1
3 1 0 1 0 1 0 1 0 1
4 1 1 1 1 1 0 0 0 0
5 0 0 0 1 0 0 1 1 1;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment