Go to the documentation of this file.
82 unsigned int _norders;
92 virtual void help(
void);
94 bool parse(
int& argc,
char* argv[]);
97 unsigned int size(
void)
const {
return _size; }
105 int*
loss(
void)
const {
return _loss; }
122 bool operator() (
int i,
int j) {
194 capacities(
opt.capacities()), ncapacities(
opt.ncapacities()),
195 maxcapacity(
opt.maxcapacity()), loss(
opt.loss()),
196 ncolors(
opt.ncolors()), orders(
opt.orders()),
199 slab(*this, norders, 0,nslabs-1),
200 slabload(*this, nslabs, 0,45),
201 slabcost(*this, nslabs, 0, Int::Limits::
max),
202 total_cost(*this, 0, Int::Limits::
max)
206 for (
unsigned int i = 0;
i < norders; ++
i) {
208 for (
int j = nslabs; j--; ) {
209 boolslab[j +
i*nslabs] = tmp[j] =
BoolVar(*
this, 0, 1);
215 for (
unsigned int s = 0; s < nslabs; ++s) {
218 for (
int i = norders;
i--; ) {
220 x[
i] = boolslab[s +
i*nslabs];
226 for (
unsigned int i = norders;
i-- ; )
233 for (
int c = ncolors;
c--; ) {
235 for (
int o = norders; o--; ) {
240 for (
unsigned int s = 0; s < nslabs; ++s) {
242 for (
int c = ncolors;
c--; ) {
246 for (
int o = norders; o--; ) {
248 hasc[
pos++] = boolslab[s + o*nslabs];
250 assert(
pos == nofcolor[
c]);
262 for (
int s = nslabs; s--; ) {
263 element(*
this,
l, slabload[s], slabcost[s]);
268 if (
opt.symmetry() == SYMMETRY_BRANCHING) {
271 }
else if (
opt.symmetry() == SYMMETRY_NONE) {
284 for (
unsigned int i = 0 ;
i < norders ;
i++)
288 for (
unsigned int i = 0 ;
i < norders ;
i++) {
289 sorted_orders[
i] = slab[indices[
i]];
298 os <<
"What slab=" << slab << std::endl;
299 os <<
"Slab load=" << slabload << std::endl;
300 os <<
"Slab cost=" << slabcost << std::endl;
301 os <<
"Total cost=" << total_cost << std::endl;
304 bool unassigned =
false;
305 for (
int i = nslabs;
i--; ) {
310 if (slabload[
i].
min()>0) ++nslabsused;
311 if (slabcost[
i].
min()>0) ++nslabscost;
314 os <<
"Number of slabs used=" << nslabsused
315 <<
", slabs with cost=" << nslabscost
323 capacities(s.capacities), ncapacities(s.ncapacities),
324 maxcapacity(s.maxcapacity), loss(s.loss),
325 ncolors(s.ncolors), orders(s.orders),
326 norders(s.norders), nslabs(s.nslabs) {
370 e << alternatives() <<
pos << val;
386 for (
unsigned int i = start;
i < sm.
norders; ++
i)
401 unsigned int pos = start;
402 for (
unsigned int i = start;
i<sm.
norders; ++
i) {
415 unsigned int val = sm.
slab[
pos].min();
417 unsigned int firstzero = 0;
422 return new Choice(*
this, (val<firstzero) ? 2 : 1,
pos, val);
425 unsigned int alt;
int pos, val;
426 e >> alt >>
pos >> val;
444 std::ostream& o)
const {
446 o <<
"slab[" <<
c.pos <<
"] "
447 << ((
a == 0) ?
"=" :
"!=")
460 return sizeof(*this);
478 Script::run<SteelMill,BAB,SteelMillOptions>(
opt);
486 std::cerr <<
"\t(string), optional" << std::endl
487 <<
"\t\tBenchmark to load." << std::endl
488 <<
"\t\tIf none is given, the standard CSPLib instance is used."
490 std::cerr <<
"\t(unsigned int), optional" << std::endl
491 <<
"\t\tNumber of orders to use, in the interval [0..norders]."
493 <<
"\t\tIf none is given, all orders are used." << std::endl;
501 std::cerr <<
"Too many arguments given, max two allowed (given={";
502 for (
int i = 1;
i < argc; ++
i) {
503 std::cerr <<
"\"" << argv[
i] <<
"\"";
504 if (
i < argc-1) std::cerr <<
",";
506 std::cerr <<
"})." << std::endl;
512 for (
int i = strlen(argv[argc-1]);
i-- && issize; )
513 issize &= (isdigit(argv[argc-1][
i]) != 0);
515 _size = atoi(argv[argc-1]);
517 std::ifstream instance(argv[argc-1]);
518 if (instance.fail()) {
519 std::cerr <<
"Argument \"" << argv[argc-1]
520 <<
"\" is neither an integer nor a readable file"
525 instance >> _ncapacities;
526 _capacities =
new int[_ncapacities];
528 for (
int i = 0;
i < _ncapacities; ++
i) {
529 instance >> _capacities[
i];
530 _maxcapacity =
std::max(_maxcapacity, _capacities[
i]);
532 instance >> _ncolors >> _norders;
533 _orders =
new int[_norders][2];
534 for (
unsigned int i = 0;
i < _norders; ++
i) {
543 _loss =
new int[_maxcapacity+1];
546 for (
int c = 1;
c < _maxcapacity; ++
c) {
547 if (
c > _capacities[currcap]) ++currcap;
548 _loss[
c] = _capacities[currcap] -
c;
556 if (_size == 0 || _size > _norders) {
557 std::cerr <<
"Size must be between 1 and " << _norders << std::endl;
@ SYMMETRY_BRANCHING
Breaking symmetries with symmetry.
int ncapacities
Number of capacities.
Post propagator for SetVar x
int * loss
Loss for all sizes.
bool me_failed(ModEvent me)
Check whether modification event me is failed.
static IntArgs create(int n, int start, int inc=1)
Allocate array with n elements such that for all .
virtual size_t dispose(Space &)
Delete brancher and return its size.
int start
Cache of first unassigned value.
virtual Actor * copy(Space &home)
Copy brancher.
Example: Steel-mill slab design problem
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
order_t orders(void) const
Return orders.
virtual void print(std::ostream &os) const
Print solution.
virtual ExecStatus commit(Space &home, const Gecode::Choice &_c, unsigned int a)
Perform commit for choice _c and alternative a.
Passing integer variables.
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
Post domain consistent propagator for .
unsigned int size(I &i)
Size of all ranges of range iterator i.
int main(int argc, char *argv[])
Main-function.
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
IntVarArray slabload
Load of slab j.
bool assigned(View x, int v)
Whether x is assigned to value v.
int * capacities(void) const
Return capacities.
IntVarBranch INT_VAR_MAX_MIN(BranchTbl tbl)
Select variable with smallest max.
static void post(Home home)
Post brancher.
Multi _c(Gecode::IntArgs({1, 2, 3}))
IntVarArray slab
Slab assigned to order i.
void 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.
Base-class for both propagators and branchers.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
@ SYMMETRY_LDSB
Use LDSB for symmetry breaking.
SteelMillOptions for examples with size option and an additional optional file name parameter.
unsigned int csplib_norders
Number of orders.
int size(void) const
Return size of array (number of elements)
const int order_weight
Weight-position in order-array elements.
virtual void help(void)
Print help text.
SteelMill(const SteelMillOptions &opt)
Actual model.
int ncapacities(void) const
Return number of capacities.
virtual Space * copy(void)
Copy during cloning.
bool assigned(void) const
Test if all variables are assigned.
virtual IntVar cost(void) const
Return solution cost.
Collection of symmetries.
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
Gecode toplevel namespace
int csplib_orders[][2]
Orders.
SteelMill(SteelMill &s)
Constructor for cloning s.
SteelMillBranch(Home home)
Construct brancher.
bool parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
int maxcapacity
Maximum capacity.
@ SYMMETRY_NONE
Simple symmetry.
Base-class for branchers.
Passing Boolean variables.
Home class for posting propagators
Parametric base-class for scripts.
int csplib_capacities[]
Constants for CSPLib instance of the Steel Mill Slab Design Problem.
IntVarArray slabcost
Cost of slab j.
Boolean integer variables.
int val
Value of variable.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
int pos
Position of variable.
int norders(void) const
Return number of orders.
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int ncolors(void) const
Return number of colors.
unsigned int nslabs
Number of slabs.
SteelMillBranch(Space &home, SteelMillBranch &b)
Copy constructor.
int(* order_t)[2]
Order-specifications.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
virtual void print(const Space &, const Gecode::Choice &_c, unsigned int a, std::ostream &o) const
Print explanation.
virtual Choice * choice(const Space &, Archive &e)
Return choice from e.
int maxcapacity(void) const
Return maximum of capacities.
Choice(const Brancher &b, unsigned int a, int pos0, int val0)
virtual void help(void)
Print help text.
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
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.
SymmetryHandle ValueSymmetry(const IntArgs &vs)
Values in v are interchangeable.
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
int ncolors
Number of colors.
Integer view for integer variables.
void symmetry(int v)
Set default symmetry value.
const int order_color
Color-position in order-array elements.
SteelMillOptions(const char *n)
Initialize options for example with name n.
order_t orders
The orders.
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
virtual bool status(const Space &home) const
Check status of brancher, return true if alternatives left.
void solutions(unsigned int n)
Set default number of solutions to search for.
unsigned int csplib_ncolors
Number of colors.
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Gecode::FloatVal c(-8, 8)
int csplib_loss[]
Loss for all sizes.
int * capacities
Capacities.
SortByWeight(order_t _orders)
Initialize orders.
int n
Number of negative literals for node type.
Choice for performing commit
@ ES_FAILED
Execution has resulted in failure.
unsigned int norders
Number of orders.
Passing integer arguments.
virtual void archive(Archive &e) const
Archive into e.
Gecode::IntArgs i({1, 2, 3, 4})
bool pos(const View &x)
Test whether x is postive.
@ ES_OK
Execution is okay.
Custom brancher for steel mill slab design.
virtual void archive(Archive &e) const
Archive into e.
virtual Gecode::Choice * choice(Space &home)
Return choice.
int * loss(void) const
Return loss values.
const FloatNum max
Largest allowed float value.
IntVar total_cost
Total cost.
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
unsigned int csplib_ncapacities
Number of capacities.
@ IRT_LQ
Less or equal ( )
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
unsigned int csplib_maxcapacity
Maximum capacity.
unsigned int size(void) const
Return size.