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

Method rsolve

contribs/qecode/Worker.cc:133–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131
132
133Strategy QWorker::rsolve(int scope,/*vector<int> assignments,*/Engine* L) {
134 access.acquire();
135 bool forget = (stopandforget==2);
136 access.release();
137 if (forget) {
138 delete L;
139 return Strategy::Dummy();
140 }
141
142 MySpace* sol = static_cast<MySpace*>(L->next());
143 Strategy ret=Strategy::Dummy();
144 bool LwasEmpty = true;
145
146
147 while ((sol != NULL) ) {
148 LwasEmpty=false;
149 vector<int> assignments = getTheValues(sol,0,sol->nbVars()-1);
150 Strategy result;
151
152 if (scope == (problem->spaces() - 1) ) { // last scope reached. Verify the goal...
153 MySpace* g = problem->getGoal();
154 for (int i=0;i<g->nbVars();i++) {
155 switch (g->type_of_v[i]) {
156 case VTYPE_INT :
157 rel(*g,*(static_cast<IntVar*>(g->v[i])) == assignments[i]);
158 break;
159 case VTYPE_BOOL :
160 rel(*g,*(static_cast<BoolVar*>(g->v[i])) == assignments[i]);
161 break;
162 default :
163 cout<<"Unknown variable type"<<endl;
164 abort();
165 }
166 }
167 Gecode::DFS<MySpace> solutions(g);
168 MySpace* goalsol = solutions.next();
169 if (goalsol == NULL) {
170 delete g;
171 delete L;
172 result = Strategy::SFalse();
173 }
174 else {
175 int vmin = ( (scope==0)? 0 : (problem->nbVarInScope(scope-1)) );
176 int vmax = (problem->nbVarInScope(scope))-1;
177 vector<int> zevalues=getTheValues(sol,vmin,vmax);
178 result=Strategy(problem->quantification(scope),vmin,vmax,scope,zevalues);
179 result.attach(Strategy::STrue());
180 delete g;
181 // delete sol;
182 delete goalsol;
183 }
184 }
185
186 else { // This is not the last scope...
187 MySpace* espace = problem->getSpace(scope+1);
188 for (int i=0;i<assignments.size();i++) {
189 switch (espace->type_of_v[i]) {
190 case VTYPE_INT :

Callers

nothing calls this directly

Calls 11

attachMethod · 0.80
getTheValuesFunction · 0.70
StrategyClass · 0.70
relFunction · 0.50
acquireMethod · 0.45
releaseMethod · 0.45
nextMethod · 0.45
spacesMethod · 0.45
getGoalMethod · 0.45
getSpaceMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected