Last active
December 20, 2015 07:39
-
-
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`
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
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