MCPcopy Create free account
hub / github.com/Gecode/gecode / QueenArmies

Method QueenArmies

examples/queen-armies.cpp:83–118  ·  view source on GitHub ↗

Constructor

Source from the content-addressed store, hash-verified

81
82 /// Constructor
83 QueenArmies(const SizeOptions& opt) :
84 IntMaximizeScript(opt),
85 n(opt.size()),
86 U(*this, IntSet::empty, IntSet(0, n*n)),
87 W(*this, IntSet::empty, IntSet(0, n*n)),
88 w(*this, n*n, 0, 1),
89 b(*this, n*n, 0, 1),
90 q(*this, 0, n*n)
91 {
92 // Basic rules of the model
93 for (int i = n*n; i--; ) {
94 // w[i] means that no blacks are allowed on A[i]
95 rel(*this, w[i] == (U || A[i]));
96 // Make sure blacks and whites are disjoint.
97 rel(*this, !w[i] || !b[i]);
98 // If i in U, then b[i] has a piece.
99 rel(*this, b[i] == (singleton(i) <= U));
100 }
101
102 // Connect optimization variable to number of pieces
103 linear(*this, w, IRT_EQ, q);
104 linear(*this, b, IRT_GQ, q);
105
106 // Connect cardinality of U to the number of black pieces.
107 IntVar unknowns = expr(*this, cardinality(U));
108 rel(*this, q <= unknowns);
109 linear(*this, b, IRT_EQ, unknowns);
110
111 if (opt.branching() == BRANCH_NAIVE) {
112 branch(*this, w, BOOL_VAR_NONE(), BOOL_VAL_MAX());
113 branch(*this, b, BOOL_VAR_NONE(), BOOL_VAL_MAX());
114 } else {
115 QueenBranch::post(*this);
116 assign(*this, b, BOOL_ASSIGN_MAX());
117 }
118 }
119 /// Constructor for cloning
120 QueenArmies(QueenArmies& s)
121 : IntMaximizeScript(s), n(s.n) {

Callers

nothing calls this directly

Calls 15

IntSetClass · 0.85
BOOL_VAR_NONEFunction · 0.85
BOOL_VAL_MAXFunction · 0.85
BOOL_ASSIGN_MAXFunction · 0.85
branchingMethod · 0.80
relFunction · 0.50
singletonFunction · 0.50
linearFunction · 0.50
exprFunction · 0.50
cardinalityFunction · 0.50
branchFunction · 0.50
postFunction · 0.50

Tested by

no test coverage detected