44 using namespace Gecode;
86 unsigned int _norders;
96 virtual void help(
void);
98 bool parse(
int& argc,
char* argv[]);
101 unsigned int size(
void)
const {
return _size; }
109 int*
loss(
void)
const {
return _loss; }
126 bool operator() (
int i,
int j) {
198 capacities(opt.capacities()), ncapacities(opt.ncapacities()),
199 maxcapacity(opt.maxcapacity()), loss(opt.loss()),
200 ncolors(opt.ncolors()), orders(opt.orders()),
201 norders(opt.
size()), nslabs(opt.
size()),
203 slab(*this, norders, 0,nslabs-1),
204 slabload(*this, nslabs, 0,45),
205 slabcost(*this, nslabs, 0, Int::Limits::
max),
206 total_cost(*this, 0, Int::Limits::
max)
210 for (
unsigned int i = 0;
i < norders; ++
i) {
212 for (
int j = nslabs; j--; ) {
213 boolslab[j +
i*nslabs] = tmp[j] =
BoolVar(*
this, 0, 1);
219 for (
unsigned int s = 0; s < nslabs; ++s) {
222 for (
int i = norders;
i--; ) {
224 x[
i] = boolslab[s +
i*nslabs];
230 for (
unsigned int i = norders;
i-- ; )
237 for (
int c = ncolors;
c--; ) {
239 for (
int o = norders; o--; ) {
244 for (
unsigned int s = 0; s < nslabs; ++s) {
246 for (
int c = ncolors;
c--; ) {
250 for (
int o = norders; o--; ) {
252 hasc[pos++] = boolslab[s + o*nslabs];
254 assert(pos == nofcolor[c]);
266 for (
int s = nslabs; s--; ) {
267 element(*
this, l, slabload[s], slabcost[s]);
272 if (opt.
symmetry() == SYMMETRY_BRANCHING) {
275 }
else if (opt.
symmetry() == SYMMETRY_NONE) {
288 for (
unsigned int i = 0 ;
i < norders ;
i++)
292 for (
unsigned int i = 0 ;
i < norders ;
i++) {
293 sorted_orders[
i] = slab[indices[
i]];
302 os <<
"What slab=" << slab << std::endl;
303 os <<
"Slab load=" << slabload << std::endl;
304 os <<
"Slab cost=" << slabcost << std::endl;
305 os <<
"Total cost=" << total_cost << std::endl;
308 bool unassigned =
false;
309 for (
int i = nslabs;
i--; ) {
314 if (slabload[
i].
min()>0) ++nslabsused;
315 if (slabcost[
i].
min()>0) ++nslabscost;
318 os <<
"Number of slabs used=" << nslabsused
319 <<
", slabs with cost=" << nslabscost
327 capacities(s.capacities), ncapacities(s.ncapacities),
328 maxcapacity(s.maxcapacity), loss(s.loss),
329 ncolors(s.ncolors), orders(s.orders),
330 norders(s.norders), nslabs(s.nslabs) {
331 slab.update(*
this, share, s.
slab);
332 slabload.update(*
this, share, s.
slabload);
333 slabcost.update(*
this, share, s.
slabcost);
334 total_cost.update(*
this, share, s.
total_cost);
370 : Gecode::
Choice(b,a),
pos(pos0), val(val0) {}
372 virtual size_t size(
void)
const {
378 e << alternatives() <<
pos << val;
387 :
Brancher(home, share, b), start(b.start) {
394 for (
unsigned int i = start;
i < sm.
norders; ++
i)
409 unsigned int pos = start;
410 for (
unsigned int i = start;
i<sm.
norders; ++
i) {
423 unsigned int val = sm.
slab[
pos].min();
425 unsigned int firstzero = 0;
430 return new Choice(*
this, (val<firstzero) ? 2 : 1, pos, val);
433 unsigned int alt;
int pos, val;
434 e >> alt >> pos >> val;
435 return new Choice(*
this, alt, pos, val);
452 std::ostream& o)
const {
454 o <<
"slab[" << c.
pos <<
"] "
455 << ((a == 0) ?
"=" :
"!=")
468 return sizeof(*this);
484 if (!opt.
parse(argc,argv))
486 Script::run<SteelMill,BAB,SteelMillOptions>(
opt);
494 std::cerr <<
"\t(string), optional" << std::endl
495 <<
"\t\tBenchmark to load." << std::endl
496 <<
"\t\tIf none is given, the standard CSPLib instance is used."
498 std::cerr <<
"\t(unsigned int), optional" << std::endl
499 <<
"\t\tNumber of orders to use, in the interval [0..norders]."
501 <<
"\t\tIf none is given, all orders are used." << std::endl;
509 std::cerr <<
"Too many arguments given, max two allowed (given={";
510 for (
int i = 1;
i < argc; ++
i) {
511 std::cerr <<
"\"" << argv[
i] <<
"\"";
512 if (
i < argc-1) std::cerr <<
",";
514 std::cerr <<
"})." << std::endl;
520 for (
int i = strlen(argv[argc-1]);
i-- && issize; )
521 issize &= (isdigit(argv[argc-1][
i]) != 0);
523 _size = atoi(argv[argc-1]);
525 std::ifstream instance(argv[argc-1]);
526 if (instance.fail()) {
527 std::cerr <<
"Argument \"" << argv[argc-1]
528 <<
"\" is neither an integer nor a readable file"
533 instance >> _ncapacities;
534 _capacities =
new int[_ncapacities];
536 for (
int i = 0;
i < _ncapacities; ++
i) {
537 instance >> _capacities[
i];
538 _maxcapacity =
std::max(_maxcapacity, _capacities[
i]);
540 instance >> _ncolors >> _norders;
541 _orders =
new int[_norders][2];
542 for (
unsigned int i = 0;
i < _norders; ++
i) {
551 _loss =
new int[_maxcapacity+1];
554 for (
int c = 1;
c < _maxcapacity; ++
c) {
555 if (
c > _capacities[currcap]) ++currcap;
556 _loss[
c] = _capacities[currcap] -
c;
564 if (_size == 0 || _size > _norders) {
565 std::cerr <<
"Size must be between 1 and " << _norders << std::endl;
int ncapacities
Number of capacities.
SteelMillBranch(Home home)
Construct brancher.
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
static IntArgs create(int n, int start, int inc=1)
Allocate array with n elements such that for all .
IntVarArray slab
Slab assigned to order i.
int val
Value of variable.
order_t orders
The orders.
unsigned int csplib_maxcapacity
Maximum capacity.
int * loss
Loss for all sizes.
Breaking symmetries with symmetry.
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatNum c)
Post propagator for .
int * capacities
Capacities.
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
const FloatNum max
Largest allowed float value.
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
unsigned int norders
Number of orders.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
int ncolors
Number of colors.
bool pos(const View &x)
Test whether x is postive.
virtual void help(void)
Print help text.
int maxcapacity
Maximum capacity.
Collection of symmetries.
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
Use LDSB for symmetry breaking.
virtual bool status(const Space &home) const
Check status of brancher, return true if alternatives left.
SortByWeight(order_t _orders)
Initialize orders.
int start
Cache of first unassigned value.
virtual Actor * copy(Space &home, bool share)
Copy brancher.
const int order_weight
Weight-position in order-array elements.
unsigned int csplib_norders
Number of orders.
IntVarArray slabcost
Cost of slab j.
virtual Space * copy(bool share)
Copy during cloning.
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.
Base-class for both propagators and branchers.
SteelMillOptions(const char *n)
Initialize options for example with name n.
virtual void print(std::ostream &os) const
Print solution.
Gecode::FloatVal c(-8, 8)
order_t orders(void) const
Return orders.
Gecode::IntArgs i(4, 1, 2, 3, 4)
Base-class for branchers.
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
int n
Number of negative literals for node type.
virtual void print(const Space &, const Gecode::Choice &_c, unsigned int a, std::ostream &o) const
Print explanation.
Execution has resulted in failure.
static BrancherHandle post(Home home)
Post brancher.
int maxcapacity(void) const
Return maximum of capacities.
SteelMillBranch(Space &home, bool share, SteelMillBranch &b)
Copy constructor.
int csplib_orders[][2]
Orders.
virtual ExecStatus commit(Space &home, const Gecode::Choice &_c, unsigned int a)
Perform commit for choice _c and alternative a.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
virtual void archive(Archive &e) const
Archive into e.
unsigned int size(I &i)
Size of all ranges of range iterator i.
SymmetryHandle ValueSymmetry(const IntArgs &vs)
Values in v are interchangeable.
IntVar total_cost
Total cost.
virtual Choice * choice(const Space &, Archive &e)
Return choice from e.
int pos
Position of variable.
int csplib_capacities[]
Constants for CSPLib instance of the Steel Mill Slab Design Problem.
struct Gecode::@519::NNF::@60::@62 a
For atomic nodes.
const int order_color
Color-position in order-array elements.
virtual Gecode::Choice * choice(Space &home)
Return choice.
int norders(void) const
Return number of orders.
int(* order_t)[2]
Order-specifications.
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntConLevel)
Post domain consistent propagator for .
unsigned int nslabs
Number of slabs.
Passing integer variables.
Passing integer arguments.
Passing Boolean variables.
int csplib_loss[]
Loss for all sizes.
int ncapacities(void) const
Return number of capacities.
Boolean integer variables.
Choice(const Brancher &b, unsigned int a, int pos0, int val0)
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
SteelMill(bool share, SteelMill &s)
Constructor for cloning s.
bool parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Integer view for integer variables.
struct Gecode::@519::NNF::@60::@61 b
For binary nodes (and, or, eqv)
virtual IntVar cost(void) const
Return solution cost.
SteelMill(const SteelMillOptions &opt)
Actual model.
Node * x
Pointer to corresponding Boolean expression node.
Choice for performing commit
virtual size_t dispose(Space &)
Delete brancher and return its size.
SteelMillOptions for examples with size option and an additional optional file name parameter...
unsigned int size(void) const
Return size.
bool assigned(View x, int v)
Whether x is assigned to value v.
void symmetry(int v)
Set default symmetry value.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
void solutions(unsigned int n)
Set default number of solutions to search for.
virtual void archive(Archive &e) const
Archive into e.
int * capacities(void) const
Return capacities.
int * loss(void) const
Return loss values.
IntVarBranch INT_VAR_MAX_MIN(BranchTbl tbl)
Select variable with smallest max.
bool assigned(void) const
Test if all variables are assigned.
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.
virtual size_t size(void) const
Report size occupied.
int ncolors(void) const
Return number of colors.
Home class for posting propagators
int size(void) const
Return size of array (number of elements)
unsigned int csplib_ncolors
Number of colors.
IntVarArray slabload
Load of slab j.
unsigned int csplib_ncapacities
Number of capacities.
Example: Steel-mill slab design problem
int main(int argc, char *argv[])
Main-function.
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Multi _c(Gecode::IntArgs(3, 1, 2, 3))
Custom brancher for steel mill slab design.
virtual void help(void)
Print help text.