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

Method post

gecode/search/nogoods.hpp:89–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87
88 template<class Path>
89 forceinline ExecStatus
90 NoGoodsProp::post(Space& home, const Path& p) {
91 int s = 0;
92 int n = std::min(p.ds.entries(),static_cast<int>(p.ngdl()));
93
94 unsigned long int n_nogood = 0;
95
96 // Eliminate the alternatives which are not no-goods at the end
97 while ((n > s) && (p.ds[n-1].truealt() == 0U))
98 n--;
99
100 // A sentinel element
101 NoNGL nn;
102 // Current no-good literal
103 NGL* c = &nn;
104
105 // Commit no-goods at the beginning
106 while ((s < n) && (p.ds[s].truealt() > 0U))
107 // Try whether this is a rightmost alternative
108 if (p.ds[s].rightmost()) {
109 // No literal needed, directly try to commit
110 home.trycommit(*p.ds[s].choice(),p.ds[s].truealt());
111 s++;
112 } else {
113 // Prune using no-good literals
114 for (unsigned int a=0U; a<p.ds[s].truealt(); a++) {
115 NGL* l = home.ngl(*p.ds[s].choice(),a);
116 // Does the brancher support no-good literals?
117 if (l == nullptr)
118 return ES_OK;
119 GECODE_ES_CHECK(l->prune(home));
120 }
121 // Add literal as root if needed and stop
122 if (NGL* l = home.ngl(*p.ds[s].choice(),p.ds[s].truealt())) {
123 c = c->add(l,false);
124 s++; break;
125 }
126 }
127
128 // There are no literals
129 if (home.failed())
130 return ES_FAILED;
131 if (s >= n)
132 return ES_OK;
133
134 // There must be at least two literals
135 assert((n-s > 1) ||
136 ((n-s == 1) && (c != &nn)));
137
138 // Remember the last leaf
139 NGL* ll = nullptr;
140
141 // Create literals
142 for (int i=s; i<n; i++) {
143 // Add leaves
144 for (unsigned int a=0U; a<p.ds[i].truealt(); a++) {
145 NGL* l = home.ngl(*p.ds[i].choice(),a);
146 if (l == nullptr) {

Callers

nothing calls this directly

Calls 13

trycommitMethod · 0.80
ngMethod · 0.80
minFunction · 0.50
entriesMethod · 0.45
ngdlMethod · 0.45
truealtMethod · 0.45
rightmostMethod · 0.45
choiceMethod · 0.45
nglMethod · 0.45
pruneMethod · 0.45
addMethod · 0.45
failedMethod · 0.45

Tested by

no test coverage detected