49 extern const int* problems[];
51 extern const unsigned int n_problems;
67 CarOptions(
const char* s)
69 _maxstall(
"-maxstall",
"Maximum numbere of stalls", 30)
75 void parse(
int& argc,
char* argv[]) {
79 int maxstall(
void)
const {
return _maxstall.
value(); }
100 template <
class View>
108 PushToEnd(
Space& home,
bool share, PushToEnd&
p);
124 template <
class View>
126 PushToEnd<View>::PushToEnd(
Space& home,
130 template <
class View>
134 (void)
new (home) PushToEnd<View>(home,x0,y0,val0);
138 template <
class View>
140 PushToEnd<View>::PushToEnd(
Space& home,
bool share, PushToEnd<View>&
p)
143 template <
class View>
149 template <
class View>
151 PushToEnd<View>::copy(
Space& home,
bool share) {
152 return new (home) PushToEnd<View>(home,share,*
this);
155 template <
class View>
160 for (
int i =
x.size();
i-- &&
x[
i].min() >= val-1; ) {
168 if (
x[i].
max() != val)
break;
170 if (max >= y.max())
break;
183 for (
int i = 0,
pos =
x.size()-1; i < y.min(); ++
i, --
pos) {
248 : problem(opt.
size()),
249 ncars(problems[problem][0]),
250 noptions(problems[problem][1]),
251 nclasses(problems[problem][2]),
252 maxstall(opt.maxstall()),
255 nstall(*this, 0, maxstall),
256 nend(*this, 0, maxstall),
257 s(*this, ncars+maxstall, 0, nclasses+1)
260 const int* probit = problems[
problem] + 3;
268 block[
i] = *probit++;
275 for (
int i = noptions; i--; ) cdata[i] =
new int[nclasses];
277 for (
int i = noptions; i--; ) n[i] = 0;
282 for (
int o = 0; o <
noptions; ++o) {
284 cdata[o][n[o]++] =
c;
289 for (
int o = noptions; o--; ) {
290 classes[o] =
IntSet(cdata[o], n[o]);
299 for (
int i = nclasses; i--; ) {
310 rel(*
this, nstall+nend == maxstall);
314 for (
int o = noptions; o--; ) {
317 for (
int i = s.
size(); i--; ) {
319 dom(*
this, s[i], classes[o], b);
322 sequence(*
this, sb, one, block[o], 0, max[o]);
326 switch (opt.propagation()) {
328 IntArgs notend(nclasses), notstallend(nclasses+1);
329 for (
int i = nclasses; i--; ) {
337 rel(*
this, (nend > i) >> (s[
pos]==endval));
341 pushtoend(*
this, s, nend, endval);
347 switch (opt.branching()) {
353 int mid = s.
size() / 2;
356 for (
int i = 1; i <= m.size()/2; ++
i) {
359 if (mid+i < s.
size())
362 assert(pos == m.size());
378 int width = nclasses > 9 ? 2 : 1;
379 const char* space = nclasses > 9 ?
" " :
"";
380 os <<
"Stall slots=" << nstall
381 <<
", End slots=" << nend << std::endl;
383 for (; i < s.
size(); ++
i) {
386 if (v == endval)
break;
387 if (v == stallval) os << space <<
"_ ";
388 else os << std::setw(width) << v <<
" ";
392 if ((i+1)%20 == 0) os << std::endl;
404 noptions(cs.noptions),
405 nclasses(cs.nclasses),
406 maxstall(cs.maxstall),
407 stallval(cs.stallval),
426 CarOptions
opt(
"CarSequencing");
435 opt.parse(argc,argv);
436 if (opt.size() >= n_problems) {
437 std::cerr <<
"Error: size must be between 0 and "
438 << n_problems-1 << std::endl;
442 Script::run<CarSequencing,BAB,CarOptions>(
opt);
471 1, 10, 1, 1, 1, 0, 0,
475 5, 15, 0, 1, 0, 0, 0,
480 10, 2, 1, 0, 1, 0, 0,
481 11, 1, 1, 1, 1, 0, 1,
482 12, 8, 0, 1, 0, 1, 0,
483 13, 3, 1, 0, 0, 1, 1,
484 14, 10, 1, 0, 0, 0, 0,
485 15, 4, 0, 1, 0, 0, 1,
486 16, 4, 0, 0, 0, 0, 1,
487 17, 2, 1, 0, 0, 0, 1,
488 18, 4, 1, 1, 0, 0, 0,
489 19, 6, 1, 1, 0, 1, 0,
490 20, 1, 1, 0, 1, 0, 1,
491 21, 1, 1, 1, 1, 1, 1,
501 0, 13, 1, 0, 0, 0, 0,
505 4, 12, 0, 0, 1, 0, 0,
510 9, 12, 1, 1, 0, 0, 0,
511 10, 8, 1, 1, 0, 1, 0,
512 11, 2, 1, 0, 0, 1, 1,
513 12, 2, 1, 1, 1, 0, 0,
514 13, 1, 0, 1, 0, 1, 1,
515 14, 4, 1, 0, 1, 0, 0,
516 15, 4, 0, 1, 0, 0, 1,
517 16, 1, 1, 1, 0, 1, 1,
518 17, 2, 1, 0, 1, 1, 0,
519 18, 1, 0, 0, 0, 0, 1,
520 19, 1, 1, 1, 1, 1, 0,
521 20, 1, 1, 1, 0, 0, 1,
522 21, 1, 0, 1, 1, 1, 0,
533 1, 11, 1, 1, 0, 0, 0,
536 4, 15, 0, 1, 0, 0, 0,
542 10, 5, 1, 0, 0, 0, 0,
543 11, 2, 1, 1, 1, 0, 1,
544 12, 6, 0, 1, 1, 0, 0,
545 13, 2, 0, 0, 1, 0, 1,
546 14, 2, 0, 1, 0, 0, 1,
547 15, 4, 1, 1, 1, 1, 0,
548 16, 3, 1, 0, 0, 0, 1,
549 17, 5, 1, 1, 0, 1, 0,
550 18, 2, 1, 1, 1, 0, 0,
551 19, 4, 1, 1, 0, 0, 1,
552 20, 1, 1, 0, 0, 1, 1,
553 21, 1, 1, 1, 0, 1, 1,
554 22, 1, 0, 1, 0, 1, 1,
555 23, 1, 0, 1, 1, 0, 1,
556 24, 2, 0, 0, 0, 0, 1,
566 0, 10, 1, 0, 0, 0, 0,
571 5, 11, 0, 1, 0, 0, 0,
576 10, 4, 1, 0, 1, 0, 0,
577 11, 7, 1, 0, 0, 1, 0,
578 12, 1, 1, 1, 1, 0, 1,
579 13, 3, 0, 1, 1, 1, 0,
580 14, 4, 0, 1, 0, 0, 1,
581 15, 5, 1, 1, 1, 0, 0,
582 16, 2, 1, 1, 0, 0, 1,
583 17, 1, 1, 0, 1, 1, 1,
584 18, 2, 1, 0, 1, 1, 0,
585 19, 3, 1, 0, 0, 0, 1,
586 20, 2, 0, 1, 1, 0, 1,
587 21, 1, 0, 1, 0, 1, 1,
588 22, 3, 1, 1, 0, 1, 0,
589 23, 1, 0, 0, 1, 1, 1,
590 24, 1, 1, 1, 1, 1, 1,
591 25, 1, 1, 1, 1, 1, 0,
609 8, 19, 0, 1, 0, 0, 0,
611 10, 10, 1, 0, 0, 0, 0,
612 11, 1, 0, 0, 1, 1, 0,
613 12, 5, 1, 1, 1, 1, 0,
614 13, 2, 1, 0, 1, 1, 0,
615 14, 6, 1, 1, 0, 0, 0,
616 15, 4, 1, 1, 1, 0, 0,
617 16, 8, 1, 0, 0, 1, 0,
618 17, 1, 1, 0, 0, 0, 1,
619 18, 4, 0, 1, 1, 0, 0,
620 19, 2, 0, 0, 0, 0, 1,
621 20, 4, 0, 1, 0, 0, 1,
622 21, 1, 1, 1, 0, 1, 1,
623 22, 1, 0, 1, 1, 0, 1,
626 const int* problems[] = {
636 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.
CarSequencing(bool share, CarSequencing &cs)
Constructor for cloning s.
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.
ExecStatus ES_SUBSUMED(Propagator &p)
const FloatNum max
Largest allowed float value.
bool one(const Gecode::FloatValArgs &a)
Check whether has only one coefficients.
void update(Space &home, bool share, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
virtual void print(std::ostream &os) const
Print solution.
Regular expressions over integer values.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
const int nclasses
Number of classes.
bool pos(const View &x)
Test whether x is postive.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Base-class for propagators.
Propagation has computed fixpoint.
Parametric base-class for scripts.
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=NULL, FznRnd *rnd=NULL)
Parse FlatZinc file fileName into fzs and return it.
virtual Space * copy(bool share)
Copy during cloning.
Base-class for both propagators and branchers.
void value(unsigned int v)
Set default value to v.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
void sequence(Home home, const IntVarArgs &x, const IntSet &s, int q, int l, int u, IntConLevel)
Post propagator for .
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Gecode::IntArgs p2(4, 4, 3, 3, 5)
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.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
unsigned int size(I &i)
Size of all ranges of range iterator i.
#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.
Boolean integer variables.
void extensional(Home home, const IntVarArgs &x, DFA dfa, IntConLevel)
Post domain consistent propagator for extensional constraint described by a DFA.
Integer view for integer variables.
const int endval
End number.
Node * x
Pointer to corresponding Boolean expression node.
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntConLevel)
Post propagator for .
int pos(int h, int w, int h1, int w1)
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.
Branch from left to right.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
int val(void) const
Return assigned value.
const int problem
Problem number.
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
virtual void constrain(const Space &_best)
Return cost.
BrancherHandle branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
IntVar nstall
Number of stalls (cost to minimize)
FloatVal max(const FloatVal &x, const FloatVal &y)
Return maximum of x and y.
Gecode::IntArgs p3(6, 4, 2, 9, 3, 7, 5)
int ModEventDelta
Modification event deltas.
FloatVal min(const FloatVal &x, const FloatVal &y)
Return minimum of x and y.
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
int size(void) const
Return size of array (number of elements)
Gecode::IntArgs p1(4, 2, 2, 2, 2)
IntVar nend
Number of end markers.