MCPcopy Create free account
hub / github.com/Gecode/gecode / parse

Method parse

examples/steel-mill.cpp:496–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494}
495
496bool
497SteelMillOptions::parse(int& argc, char* argv[]) {
498 Options::parse(argc,argv);
499 // Check number of arguments
500 if (argc >= 4) {
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 << ",";
505 }
506 std::cerr << "})." << std::endl;
507 return false;
508 }
509 // Parse options
510 while (argc >= 2) {
511 bool issize = true;
512 for (int i = strlen(argv[argc-1]); i-- && issize; )
513 issize &= (isdigit(argv[argc-1][i]) != 0);
514 if (issize) {
515 _size = atoi(argv[argc-1]);
516 } else {
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"
521 << std::endl;
522 return false;
523 }
524 // Read file instance
525 instance >> _ncapacities;
526 _capacities = new int[_ncapacities];
527 _maxcapacity = -1;
528 for (int i = 0; i < _ncapacities; ++i) {
529 instance >> _capacities[i];
530 _maxcapacity = std::max(_maxcapacity, _capacities[i]);
531 }
532 instance >> _ncolors >> _norders;
533 _orders = new int[_norders][2];
534 for (unsigned int i = 0; i < _norders; ++i) {
535 instance >> _orders[i][order_weight] >> _orders[i][order_color];
536 }
537 }
538
539 --argc;
540 }
541 // Compute loss
542 {
543 _loss = new int[_maxcapacity+1];
544 _loss[0] = 0;
545 int currcap = 0;
546 for (int c = 1; c < _maxcapacity; ++c) {
547 if (c > _capacities[currcap]) ++currcap;
548 _loss[c] = _capacities[currcap] - c;
549 }
550 }
551 // Set size, if none given
552 if (_size == 0) {
553 _size = _norders;

Callers 15

mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 3

parseFunction · 0.85
maxFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected