45 extern const int* problems[];
47 extern const unsigned int n_problems;
63 CarOptions(
const char* s)
65 _maxstall(
"maxstall",
"Maximum numbere of stalls", 30)
71 void parse(
int& argc,
char* argv[]) {
75 int maxstall(
void)
const {
return _maxstall.
value(); }
104 PushToEnd(
Space& home, PushToEnd&
p);
120 template <
class View>
122 PushToEnd<View>::PushToEnd(
Space& home,
126 template <
class View>
130 (void)
new (home) PushToEnd<View>(home,x0,y0,val0);
134 template <
class View>
136 PushToEnd<View>::PushToEnd(
Space& home, PushToEnd<View>&
p)
139 template <
class View>
145 template <
class View>
147 PushToEnd<View>::copy(
Space& home) {
148 return new (home) PushToEnd<View>(home,*
this);
151 template <
class View>
166 if (max >=
y.max())
break;
246 ncars(problems[problem][0]),
247 noptions(problems[problem][1]),
248 nclasses(problems[problem][2]),
249 maxstall(opt.maxstall()),
252 nstall(*this, 0, maxstall),
253 nend(*this, 0, maxstall),
254 s(*this, ncars+maxstall, 0, nclasses+1)
257 const int* probit = problems[problem] + 3;
261 for (
int i = 0; i < noptions; ++
i ) {
264 for (
int i = 0; i < noptions; ++
i ) {
265 block[
i] = *probit++;
271 int** cdata =
new int*[noptions];
272 for (
int i = noptions; i--; ) cdata[i] =
new int[nclasses];
273 int*
n =
new int[noptions];
274 for (
int i = noptions; i--; ) n[i] = 0;
276 for (
int c = 0;
c < nclasses; ++
c) {
279 for (
int o = 0; o < noptions; ++o) {
281 cdata[o][n[o]++] =
c;
286 for (
int o = noptions; o--; ) {
287 classes[o] =
IntSet(cdata[o], n[o]);
296 for (
int i = nclasses; i--; ) {
299 c[stallval] =
IntSet(0, maxstall);
300 c[ endval] =
IntSet(0, maxstall);
307 rel(*
this, nstall+nend == maxstall);
311 for (
int o = noptions; o--; ) {
314 for (
int i = s.
size(); i--; ) {
316 dom(*
this, s[i], classes[o], b);
319 sequence(*
this, sb, one, block[o], 0, max[o]);
323 switch (opt.propagation()) {
325 IntArgs notend(nclasses), notstallend(nclasses+1);
326 for (
int i = nclasses; i--; ) {
330 notstallend[nclasses] = stallval;
333 for (
int pos = s.
size()-1, i = 0; i < maxstall; ++
i, --
pos) {
334 rel(*
this, (nend > i) >> (s[
pos]==endval));
338 pushtoend(*
this, s, nend, endval);
344 switch (opt.branching()) {
348 case BRANCH_MIDDLE: {
350 int mid = s.
size() / 2;
353 for (
int i = 1; i <= m.size()/2; ++
i) {
356 if (mid+i < s.
size())
359 assert(pos == m.size());
375 int width = nclasses > 9 ? 2 : 1;
376 const char* space = nclasses > 9 ?
" " :
"";
377 os <<
"Stall slots=" << nstall
378 <<
", End slots=" << nend << std::endl;
380 for (; i < s.
size(); ++
i) {
383 if (v == endval)
break;
384 if (v == stallval) os << space <<
"_ ";
385 else os << std::setw(width) << v <<
" ";
389 if ((i+1)%20 == 0) os << std::endl;
401 noptions(cs.noptions),
402 nclasses(cs.nclasses),
403 maxstall(cs.maxstall),
404 stallval(cs.stallval),
423 CarOptions
opt(
"CarSequencing");
432 opt.parse(argc,argv);
433 if (opt.size() >= n_problems) {
434 std::cerr <<
"Error: size must be between 0 and " 435 << n_problems-1 << std::endl;
439 Script::run<CarSequencing,BAB,CarOptions>(
opt);
468 1, 10, 1, 1, 1, 0, 0,
472 5, 15, 0, 1, 0, 0, 0,
477 10, 2, 1, 0, 1, 0, 0,
478 11, 1, 1, 1, 1, 0, 1,
479 12, 8, 0, 1, 0, 1, 0,
480 13, 3, 1, 0, 0, 1, 1,
481 14, 10, 1, 0, 0, 0, 0,
482 15, 4, 0, 1, 0, 0, 1,
483 16, 4, 0, 0, 0, 0, 1,
484 17, 2, 1, 0, 0, 0, 1,
485 18, 4, 1, 1, 0, 0, 0,
486 19, 6, 1, 1, 0, 1, 0,
487 20, 1, 1, 0, 1, 0, 1,
488 21, 1, 1, 1, 1, 1, 1,
498 0, 13, 1, 0, 0, 0, 0,
502 4, 12, 0, 0, 1, 0, 0,
507 9, 12, 1, 1, 0, 0, 0,
508 10, 8, 1, 1, 0, 1, 0,
509 11, 2, 1, 0, 0, 1, 1,
510 12, 2, 1, 1, 1, 0, 0,
511 13, 1, 0, 1, 0, 1, 1,
512 14, 4, 1, 0, 1, 0, 0,
513 15, 4, 0, 1, 0, 0, 1,
514 16, 1, 1, 1, 0, 1, 1,
515 17, 2, 1, 0, 1, 1, 0,
516 18, 1, 0, 0, 0, 0, 1,
517 19, 1, 1, 1, 1, 1, 0,
518 20, 1, 1, 1, 0, 0, 1,
519 21, 1, 0, 1, 1, 1, 0,
530 1, 11, 1, 1, 0, 0, 0,
533 4, 15, 0, 1, 0, 0, 0,
539 10, 5, 1, 0, 0, 0, 0,
540 11, 2, 1, 1, 1, 0, 1,
541 12, 6, 0, 1, 1, 0, 0,
542 13, 2, 0, 0, 1, 0, 1,
543 14, 2, 0, 1, 0, 0, 1,
544 15, 4, 1, 1, 1, 1, 0,
545 16, 3, 1, 0, 0, 0, 1,
546 17, 5, 1, 1, 0, 1, 0,
547 18, 2, 1, 1, 1, 0, 0,
548 19, 4, 1, 1, 0, 0, 1,
549 20, 1, 1, 0, 0, 1, 1,
550 21, 1, 1, 1, 0, 1, 1,
551 22, 1, 0, 1, 0, 1, 1,
552 23, 1, 0, 1, 1, 0, 1,
553 24, 2, 0, 0, 0, 0, 1,
563 0, 10, 1, 0, 0, 0, 0,
568 5, 11, 0, 1, 0, 0, 0,
573 10, 4, 1, 0, 1, 0, 0,
574 11, 7, 1, 0, 0, 1, 0,
575 12, 1, 1, 1, 1, 0, 1,
576 13, 3, 0, 1, 1, 1, 0,
577 14, 4, 0, 1, 0, 0, 1,
578 15, 5, 1, 1, 1, 0, 0,
579 16, 2, 1, 1, 0, 0, 1,
580 17, 1, 1, 0, 1, 1, 1,
581 18, 2, 1, 0, 1, 1, 0,
582 19, 3, 1, 0, 0, 0, 1,
583 20, 2, 0, 1, 1, 0, 1,
584 21, 1, 0, 1, 0, 1, 1,
585 22, 3, 1, 1, 0, 1, 0,
586 23, 1, 0, 0, 1, 1, 1,
587 24, 1, 1, 1, 1, 1, 1,
588 25, 1, 1, 1, 1, 1, 0,
606 8, 19, 0, 1, 0, 0, 0,
608 10, 10, 1, 0, 0, 0, 0,
609 11, 1, 0, 0, 1, 1, 0,
610 12, 5, 1, 1, 1, 1, 0,
611 13, 2, 1, 0, 1, 1, 0,
612 14, 6, 1, 1, 0, 0, 0,
613 15, 4, 1, 1, 1, 0, 0,
614 16, 8, 1, 0, 0, 1, 0,
615 17, 1, 1, 0, 0, 0, 1,
616 18, 4, 0, 1, 1, 0, 0,
617 19, 2, 0, 0, 0, 0, 1,
618 20, 4, 0, 1, 0, 0, 1,
619 21, 1, 1, 1, 0, 1, 1,
620 22, 1, 0, 1, 1, 0, 1,
623 const int* problems[] = {
633 const unsigned int n_problems =
sizeof(problems)/
sizeof(
int*);
Options for scripts with additional size parameter
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
const int noptions
Number of options.
void sequence(Home home, const IntVarArgs &x, const IntSet &s, int q, int l, int u, IntPropLevel)
Post propagator for .
ExecStatus ES_SUBSUMED(Propagator &p)
int size(void) const
Return size of array (number of elements)
const FloatNum max
Largest allowed float value.
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel)
Post propagator for .
bool one(const Gecode::FloatValArgs &a)
Check whether has only one coefficients.
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
Regular expressions over integer values.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=NULL, Rnd &rnd=defrnd)
Parse FlatZinc file fileName into fzs and return it.
static int val(const Space &, IntVar x, int)
Value selection function for branching.
const int nclasses
Number of classes.
bool assigned(void) const
Test if all variables are assigned.
bool pos(const View &x)
Test whether x is postive.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Base-class for propagators.
IntVarArray x
Card at position.
Propagation has computed fixpoint.
Parametric base-class for scripts.
Base-class for both propagators and branchers.
void value(unsigned int v)
Set default value to v.
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
const FloatNum min
Smallest allowed float value.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
int main(int argc, char *argv[])
Main-function.
const int maxstall
Maximum number of stalls.
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
void extensional(Home home, const IntVarArgs &x, DFA dfa, IntPropLevel)
Post domain consistent propagator for extensional constraint described by a DFA.
int val(void) const
Return assigned value.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
unsigned int size(I &i)
Size of all ranges of range iterator i.
void branch(Home home, const IntVarArgs &x, const BoolVarArgs &y, IntBoolVarBranch vars, IntValBranch vals)
Branch function for integer and Boolean variables.
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Passing integer variables.
const int ncars
Number of cars.
Passing integer arguments.
Passing Boolean variables.
CarSequencing(CarSequencing &cs)
Constructor for cloning s.
Branch from left to right.
Boolean integer variables.
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Integer view for integer variables.
const int endval
End number.
IntVarArray y
Position of card.
IntVarArray s
Sequence of cars produced.
const int stallval
Stall number.
bool assigned(View x, int v)
Whether x is assigned to value v.
CarSequencing(const CarOptions &opt)
Initial model.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
const int problem
Problem number.
virtual Space * copy(void)
Copy during cloning.
Gecode toplevel namespace
virtual void constrain(const Space &_best)
Return cost.
IntVar nstall
Number of stalls (cost to minimize)
int ModEventDelta
Modification event deltas.
virtual void print(std::ostream &os) const
Print solution.
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
IntVar nend
Number of end markers.