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) {
250 ncars(problems[problem][0]),
251 noptions(problems[problem][1]),
252 nclasses(problems[problem][2]),
253 maxstall(opt.maxstall()),
256 nstall(*this, 0, maxstall),
257 nend(*this, 0, maxstall),
258 s(*this, ncars+maxstall, 0, nclasses+1)
261 const int* probit = problems[
problem] + 3;
269 block[
i] = *probit++;
276 for (
int i = noptions; i--; ) cdata[i] =
new int[nclasses];
278 for (
int i = noptions; i--; ) n[i] = 0;
283 for (
int o = 0; o <
noptions; ++o) {
285 cdata[o][n[o]++] =
c;
290 for (
int o = noptions; o--; ) {
291 classes[o] =
IntSet(cdata[o], n[o]);
300 for (
int i = nclasses; i--; ) {
311 rel(*
this, nstall+nend == maxstall);
315 for (
int o = noptions; o--; ) {
318 for (
int i = s.
size(); i--; ) {
320 dom(*
this, s[i], classes[o], b);
323 sequence(*
this, sb, one, block[o], 0, max[o]);
327 switch (opt.propagation()) {
329 IntArgs notend(nclasses), notstallend(nclasses+1);
330 for (
int i = nclasses; i--; ) {
338 rel(*
this, (nend > i) >> (s[
pos]==endval));
342 pushtoend(*
this, s, nend, endval);
348 switch (opt.branching()) {
354 int mid = s.
size() / 2;
357 for (
int i = 1; i <= m.size()/2; ++
i) {
360 if (mid+i < s.
size())
363 assert(pos == m.size());
379 int width = nclasses > 9 ? 2 : 1;
380 const char* space = nclasses > 9 ?
" " :
"";
381 os <<
"Stall slots=" << nstall
382 <<
", End slots=" << nend << std::endl;
384 for (; i < s.
size(); ++
i) {
387 if (v == endval)
break;
388 if (v == stallval) os << space <<
"_ ";
389 else os << std::setw(width) << v <<
" ";
393 if ((i+1)%20 == 0) os << std::endl;
405 noptions(cs.noptions),
406 nclasses(cs.nclasses),
407 maxstall(cs.maxstall),
408 stallval(cs.stallval),
427 CarOptions
opt(
"CarSequencing");
436 opt.parse(argc,argv);
437 if (opt.size() >= n_problems) {
438 std::cerr <<
"Error: size must be between 0 and "
439 << n_problems-1 << std::endl;
443 Script::run<CarSequencing,BAB,CarOptions>(
opt);
472 1, 10, 1, 1, 1, 0, 0,
476 5, 15, 0, 1, 0, 0, 0,
481 10, 2, 1, 0, 1, 0, 0,
482 11, 1, 1, 1, 1, 0, 1,
483 12, 8, 0, 1, 0, 1, 0,
484 13, 3, 1, 0, 0, 1, 1,
485 14, 10, 1, 0, 0, 0, 0,
486 15, 4, 0, 1, 0, 0, 1,
487 16, 4, 0, 0, 0, 0, 1,
488 17, 2, 1, 0, 0, 0, 1,
489 18, 4, 1, 1, 0, 0, 0,
490 19, 6, 1, 1, 0, 1, 0,
491 20, 1, 1, 0, 1, 0, 1,
492 21, 1, 1, 1, 1, 1, 1,
502 0, 13, 1, 0, 0, 0, 0,
506 4, 12, 0, 0, 1, 0, 0,
511 9, 12, 1, 1, 0, 0, 0,
512 10, 8, 1, 1, 0, 1, 0,
513 11, 2, 1, 0, 0, 1, 1,
514 12, 2, 1, 1, 1, 0, 0,
515 13, 1, 0, 1, 0, 1, 1,
516 14, 4, 1, 0, 1, 0, 0,
517 15, 4, 0, 1, 0, 0, 1,
518 16, 1, 1, 1, 0, 1, 1,
519 17, 2, 1, 0, 1, 1, 0,
520 18, 1, 0, 0, 0, 0, 1,
521 19, 1, 1, 1, 1, 1, 0,
522 20, 1, 1, 1, 0, 0, 1,
523 21, 1, 0, 1, 1, 1, 0,
534 1, 11, 1, 1, 0, 0, 0,
537 4, 15, 0, 1, 0, 0, 0,
543 10, 5, 1, 0, 0, 0, 0,
544 11, 2, 1, 1, 1, 0, 1,
545 12, 6, 0, 1, 1, 0, 0,
546 13, 2, 0, 0, 1, 0, 1,
547 14, 2, 0, 1, 0, 0, 1,
548 15, 4, 1, 1, 1, 1, 0,
549 16, 3, 1, 0, 0, 0, 1,
550 17, 5, 1, 1, 0, 1, 0,
551 18, 2, 1, 1, 1, 0, 0,
552 19, 4, 1, 1, 0, 0, 1,
553 20, 1, 1, 0, 0, 1, 1,
554 21, 1, 1, 1, 0, 1, 1,
555 22, 1, 0, 1, 0, 1, 1,
556 23, 1, 0, 1, 1, 0, 1,
557 24, 2, 0, 0, 0, 0, 1,
567 0, 10, 1, 0, 0, 0, 0,
572 5, 11, 0, 1, 0, 0, 0,
577 10, 4, 1, 0, 1, 0, 0,
578 11, 7, 1, 0, 0, 1, 0,
579 12, 1, 1, 1, 1, 0, 1,
580 13, 3, 0, 1, 1, 1, 0,
581 14, 4, 0, 1, 0, 0, 1,
582 15, 5, 1, 1, 1, 0, 0,
583 16, 2, 1, 1, 0, 0, 1,
584 17, 1, 1, 0, 1, 1, 1,
585 18, 2, 1, 0, 1, 1, 0,
586 19, 3, 1, 0, 0, 0, 1,
587 20, 2, 0, 1, 1, 0, 1,
588 21, 1, 0, 1, 0, 1, 1,
589 22, 3, 1, 1, 0, 1, 0,
590 23, 1, 0, 0, 1, 1, 1,
591 24, 1, 1, 1, 1, 1, 1,
592 25, 1, 1, 1, 1, 1, 0,
610 8, 19, 0, 1, 0, 0, 0,
612 10, 10, 1, 0, 0, 0, 0,
613 11, 1, 0, 0, 1, 1, 0,
614 12, 5, 1, 1, 1, 1, 0,
615 13, 2, 1, 0, 1, 1, 0,
616 14, 6, 1, 1, 0, 0, 0,
617 15, 4, 1, 1, 1, 0, 0,
618 16, 8, 1, 0, 0, 1, 0,
619 17, 1, 1, 0, 0, 0, 1,
620 18, 4, 0, 1, 1, 0, 0,
621 19, 2, 0, 0, 0, 0, 1,
622 20, 4, 0, 1, 0, 0, 1,
623 21, 1, 1, 1, 0, 1, 1,
624 22, 1, 0, 1, 1, 0, 1,
627 const int* problems[] = {
637 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.
struct Gecode::@519::NNF::@60::@61 b
For binary nodes (and, or, eqv)
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.
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.