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) {
197 capacities(opt.capacities()), ncapacities(opt.ncapacities()),
198 maxcapacity(opt.maxcapacity()), loss(opt.loss()),
199 ncolors(opt.ncolors()), orders(opt.orders()),
200 norders(opt.
size()), nslabs(opt.
size()),
202 slab(*this, norders, 0,nslabs-1),
203 slabload(*this, nslabs, 0,45),
204 slabcost(*this, nslabs, 0, Int::Limits::
max),
205 total_cost(*this, 0, Int::Limits::
max)
209 for (
unsigned int i = 0;
i < norders; ++
i) {
211 for (
int j = nslabs; j--; ) {
212 boolslab[j +
i*nslabs] = tmp[j] =
BoolVar(*
this, 0, 1);
218 for (
unsigned int s = 0; s < nslabs; ++s) {
221 for (
int i = norders;
i--; ) {
223 x[
i] = boolslab[s +
i*nslabs];
229 for (
unsigned int i = norders;
i-- ; )
236 for (
int c = ncolors;
c--; ) {
238 for (
int o = norders; o--; ) {
243 for (
unsigned int s = 0; s < nslabs; ++s) {
245 for (
int c = ncolors;
c--; ) {
249 for (
int o = norders; o--; ) {
251 hasc[pos++] = boolslab[s + o*nslabs];
253 assert(pos == nofcolor[c]);
265 for (
int s = nslabs; s--; ) {
266 element(*
this, l, slabload[s], slabcost[s]);
271 if (opt.
symmetry() == SYMMETRY_BRANCHING) {
274 }
else if (opt.
symmetry() == SYMMETRY_NONE) {
287 for (
unsigned int i = 0 ;
i < norders ;
i++)
291 for (
unsigned int i = 0 ;
i < norders ;
i++) {
292 sorted_orders[
i] = slab[indices[
i]];
301 os <<
"What slab=" << slab << std::endl;
302 os <<
"Slab load=" << slabload << std::endl;
303 os <<
"Slab cost=" << slabcost << std::endl;
304 os <<
"Total cost=" << total_cost << std::endl;
307 bool unassigned =
false;
308 for (
int i = nslabs;
i--; ) {
313 if (slabload[
i].
min()>0) ++nslabsused;
314 if (slabcost[
i].
min()>0) ++nslabscost;
317 os <<
"Number of slabs used=" << nslabsused
318 <<
", slabs with cost=" << nslabscost
326 capacities(s.capacities), ncapacities(s.ncapacities),
327 maxcapacity(s.maxcapacity), loss(s.loss),
328 ncolors(s.ncolors), orders(s.orders),
329 norders(s.norders), nslabs(s.nslabs) {
330 slab.update(*
this, share, s.
slab);
331 slabload.update(*
this, share, s.
slabload);
332 slabcost.update(*
this, share, s.
slabcost);
333 total_cost.update(*
this, share, s.
total_cost);
369 : Gecode::
Choice(b,a),
pos(pos0), val(val0) {}
371 virtual size_t size(
void)
const {
377 e << alternatives() <<
pos << val;
386 :
Brancher(home, share, b), start(b.start) {
393 for (
unsigned int i = start;
i < sm.
norders; ++
i)
408 unsigned int pos = start;
409 for (
unsigned int i = start;
i<sm.
norders; ++
i) {
422 unsigned int val = sm.
slab[
pos].min();
424 unsigned int firstzero = 0;
429 return new Choice(*
this, (val<firstzero) ? 2 : 1, pos, val);
432 unsigned int alt;
int pos, val;
433 e >> alt >> pos >> val;
434 return new Choice(*
this, alt, pos, val);
458 return sizeof(*this);
474 if (!opt.
parse(argc,argv))
476 Script::run<SteelMill,BAB,SteelMillOptions>(
opt);
484 std::cerr <<
"\t(string), optional" << std::endl
485 <<
"\t\tBenchmark to load." << std::endl
486 <<
"\t\tIf none is given, the standard CSPLib instance is used."
488 std::cerr <<
"\t(unsigned int), optional" << std::endl
489 <<
"\t\tNumber of orders to use, in the interval [0..norders]."
491 <<
"\t\tIf none is given, all orders are used." << std::endl;
499 std::cerr <<
"Too many arguments given, max two allowed (given={";
500 for (
int i = 1;
i < argc; ++
i) {
501 std::cerr <<
"\"" << argv[
i] <<
"\"";
502 if (
i < argc-1) std::cerr <<
",";
504 std::cerr <<
"})." << std::endl;
510 for (
int i = strlen(argv[argc-1]);
i-- && issize; )
511 issize &= (isdigit(argv[argc-1][
i]) != 0);
513 _size = atoi(argv[argc-1]);
515 std::ifstream instance(argv[argc-1]);
516 if (instance.fail()) {
517 std::cerr <<
"Argument \"" << argv[argc-1]
518 <<
"\" is neither an integer nor a readable file"
523 instance >> _ncapacities;
524 _capacities =
new int[_ncapacities];
526 for (
int i = 0;
i < _ncapacities; ++
i) {
527 instance >> _capacities[
i];
528 _maxcapacity =
std::max(_maxcapacity, _capacities[
i]);
530 instance >> _ncolors >> _norders;
531 _orders =
new int[_norders][2];
532 for (
unsigned int i = 0;
i < _norders; ++
i) {
541 _loss =
new int[_maxcapacity+1];
544 for (
int c = 1;
c < _maxcapacity; ++
c) {
545 if (
c > _capacities[currcap]) ++currcap;
546 _loss[
c] = _capacities[currcap] -
c;
554 if (_size == 0 || _size > _norders) {
555 std::cerr <<
"Size must be between 1 and " << _norders << std::endl;