Scippy

SCIP

Solving Constraint Integer Programs

reader_sto.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file reader_sto.c
17  * @brief STO file reader - the stochastic information of an instance in SMPS format
18  * @author Stephen J. Maher
19  */
20 
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include "blockmemshell/memory.h"
25 #include "scip/benders_default.h"
26 #include "scip/cons_linear.h"
27 #include "scip/pub_cons.h"
28 #include "scip/pub_fileio.h"
29 #include "scip/pub_message.h"
30 #include "scip/pub_misc.h"
31 #include "scip/pub_reader.h"
32 #include "scip/pub_var.h"
33 #include "scip/reader_cor.h"
34 #include "scip/reader_sto.h"
35 #include "scip/reader_tim.h"
36 #include "scip/scip_cons.h"
37 #include "scip/scip_debug.h"
38 #include "scip/scipdefplugins.h"
39 #include "scip/scip_general.h"
40 #include "scip/scip_mem.h"
41 #include "scip/scip_message.h"
42 #include "scip/scip_numerics.h"
43 #include "scip/scip_param.h"
44 #include "scip/scip_prob.h"
45 #include "scip/scip_reader.h"
46 #include "scip/scip_var.h"
47 #include <stdlib.h>
48 #include <string.h>
49 
50 #define READER_NAME "storeader"
51 #define READER_DESC "file reader for stochastic information of stochastic programs in the SMPS file format"
52 #define READER_EXTENSION "sto"
53 
54 #define DEFAULT_USEBENDERS FALSE /**< should Benders' decomposition be used for the stochastic program? */
55 
56 /*
57  * sto reader internal methods
58  */
59 
60 #define STO_MAX_LINELEN 1024
61 #define STO_MAX_NAMELEN 256
62 
63 #define STO_DEFAULT_ARRAYSIZE 100
64 #define STO_DEFAULT_ENTRIESSIZE 20
65 #define STO_DEFAULT_BLOCKARRAYSIZE 5
66 #define STO_DEFAULT_CHILDRENSIZE 5
67 
68 #define BLANK ' '
69 
70 typedef struct StoScenario STOSCENARIO;
71 
72 /** STO reading data */
73 struct SCIP_ReaderData
74 {
75  SCIP_Bool usebenders;
76  STOSCENARIO* scenariotree; /**< the multi stage scenario tree */
77  int numscenarios; /**< the total number of scenarios in the scenario tree */
78 };
79 
80 
82 {
83  SCIP* scip; /**< the SCIP instance for the scenario. Used for benders. */
84  SCIP** subproblems; /**< the SCIP instances for the subproblems */
85  STOSCENARIO* parent; /**< parent scenario. */
86  STOSCENARIO** children; /**< children scenarios. */
87  int nchildren; /**< the number of children scenarios. */
88  int childrensize; /**< the size of the children array. */
89  int nsubproblems; /**< the number of subproblems */
90  int stagenum; /**< the number of the stage */
91  int scenarionum; /**< the scenario number of this stage */
92  const char* stagename; /**< the stage name */
93  const char* name; /**< the scenario name. */
94  SCIP_Real probability; /**< the probability for this scenario. */
95  /* the following describes the modifications to the constraint matrix and rhs for each scenario. */
96  const char** rownames; /**< the names of the rows with a changed value. */
97  const char** colnames; /**< the names of the columns with a changed value. */
98  SCIP_Real* values; /**< the values for the given row/column pair. */
99  int nentries; /**< the number of row/column pairs */
100  int entriessize; /**< the size of the row/colum arrays */
101 };
102 
103 
104 
105 /** enum containing all sto sections */
107 {
113 };
114 typedef enum StoSection STOSECTION;
115 
116 /** enum containing the types of stochastic information */
118 {
125 };
127 
128 /** sto input structure */
129 struct StoInput
130 {
134  int lineno;
136  char buf[STO_MAX_LINELEN];
137  const char* f0;
138  const char* f1;
139  const char* f2;
140  const char* f3;
141  const char* f4;
142  const char* f5;
143  char probname[STO_MAX_NAMELEN];
144  char stochtype[STO_MAX_NAMELEN];
145 };
146 typedef struct StoInput STOINPUT;
147 
148 /** creates a scenario structure */
149 static
151  SCIP* scip, /**< SCIP data structure */
152  STOSCENARIO** scenariodata /**< the scenario to be created */
153  )
154 {
155  assert(scip != NULL);
156 
157  SCIPdebugMessage("Creating scenario data.\n");
158 
159  SCIP_CALL( SCIPallocBlockMemory(scip, scenariodata) );
160 
161  (*scenariodata)->scip = NULL;
162  (*scenariodata)->subproblems = NULL;
163  (*scenariodata)->parent = NULL;
164  (*scenariodata)->nchildren = 0;
165  (*scenariodata)->childrensize = STO_DEFAULT_CHILDRENSIZE;
166  (*scenariodata)->nsubproblems = 0;
167  (*scenariodata)->stagenum = -1;
168  (*scenariodata)->scenarionum = -1;
169  (*scenariodata)->stagename = NULL;
170  (*scenariodata)->name = NULL;
171  (*scenariodata)->probability = 1.0;
172  (*scenariodata)->nentries = 0;
173  (*scenariodata)->entriessize = STO_DEFAULT_ENTRIESSIZE;
174 
175  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(*scenariodata)->children, (*scenariodata)->childrensize) );
176  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(*scenariodata)->rownames, (*scenariodata)->entriessize) );
177  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(*scenariodata)->colnames, (*scenariodata)->entriessize) );
178  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(*scenariodata)->values, (*scenariodata)->entriessize) );
179 
180  return SCIP_OKAY;
181 }
182 
183 /** frees the memory used for the scenario tree */
184 static
186  SCIP* scip, /**< the SCIP data structure */
187  STOSCENARIO** scenariotree /**< the scenario tree */
188  )
189 {
190  int i;
191 
192  assert(scip != NULL);
193 
194  SCIPdebugMessage("Freeing scenario <%s> in stage <%s>\n", (*scenariotree)->name,
195  (*scenariotree)->stagename);
196 
197  while( (*scenariotree)->nchildren > 0 )
198  {
199  SCIP_CALL( freeScenarioTree(scip, &(*scenariotree)->children[(*scenariotree)->nchildren - 1]) );
200  (*scenariotree)->nchildren--;
201  }
202 
203  for( i = (*scenariotree)->nentries - 1; i >= 0; i-- )
204  {
205  SCIPfreeBlockMemoryArray(scip, &(*scenariotree)->colnames[i], strlen((*scenariotree)->colnames[i]) + 1);
206  SCIPfreeBlockMemoryArray(scip, &(*scenariotree)->rownames[i], strlen((*scenariotree)->rownames[i]) + 1);
207  }
208 
209  SCIPfreeBlockMemoryArray(scip, &(*scenariotree)->values, (*scenariotree)->entriessize);
210  SCIPfreeBlockMemoryArray(scip, &(*scenariotree)->colnames, (*scenariotree)->entriessize);
211  SCIPfreeBlockMemoryArray(scip, &(*scenariotree)->rownames, (*scenariotree)->entriessize);
212  SCIPfreeBlockMemoryArray(scip, &(*scenariotree)->children, (*scenariotree)->childrensize);
213 
214  SCIPfreeBlockMemoryArray(scip, &(*scenariotree)->name, strlen((*scenariotree)->name) + 1);
215  SCIPfreeBlockMemoryArray(scip, &(*scenariotree)->stagename, strlen((*scenariotree)->stagename) + 1);
216 
217  for( i = (*scenariotree)->nsubproblems - 1; i >= 0; i-- )
218  SCIP_CALL( SCIPfree(&(*scenariotree)->subproblems[i]) );
219 
220  if( (*scenariotree)->nsubproblems > 0 )
221  SCIPfreeBlockMemoryArray(scip, &(*scenariotree)->subproblems, (*scenariotree)->nchildren);
222 
223  SCIPfreeBlockMemory(scip, scenariotree);
224 
225  return SCIP_OKAY;
226 }
227 
228 /** sets the SCIP pointer to the scenario */
229 static
231  STOSCENARIO* scenario, /**< the scenario */
232  SCIP* scip /**< the SCIP data structure */
233  )
234 {
235  assert(scenario != NULL);
236  assert(scip != NULL);
237 
238  scenario->scip = scip;
239 }
240 
241 /** returns the SCIP pointer to the scenario */
242 static
244  STOSCENARIO* scenario /**< the scenario */
245  )
246 {
247  assert(scenario != NULL);
248 
249  return scenario->scip;
250 }
251 
252 /** creates the subproblem array. This array will be the same size as the number of children */
253 static
255  SCIP* scip, /**< the SCIP data structure */
256  STOSCENARIO* scenario /**< the scenario */
257  )
258 {
259  assert(scip != NULL);
260  assert(scenario != NULL);
261 
262  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &scenario->subproblems, scenario->nchildren) );
263 
264  return SCIP_OKAY;
265 }
266 
267 /** adds a scenario to the subproblem array */
268 static
270  STOSCENARIO* scenario, /**< the scenario */
271  SCIP* subproblem /**< the subproblems data structure */
272  )
273 {
274  assert(scenario != NULL);
275  assert(subproblem != NULL);
276 
277  assert(scenario->nsubproblems + 1 <= scenario->nchildren);
278 
279  scenario->subproblems[scenario->nsubproblems] = subproblem;
280  scenario->nsubproblems++;
281 }
282 
283 /** returns the subproblem array for the scenario */
284 static
286  STOSCENARIO* scenario /**< the scenario */
287  )
288 {
289  assert(scenario != NULL);
290 
291  return scenario->subproblems;
292 }
293 
294 /** returns the number of children for a given scenario */
295 static
297  STOSCENARIO* scenario /**< the scenario */
298  )
299 {
300  assert(scenario != NULL);
301 
302  return scenario->nchildren;
303 }
304 
305 /** returns a given child for a given scenario */
306 static
308  STOSCENARIO* scenario, /**< the scenario */
309  int childnum /**< the number of the desired child */
310  )
311 {
312  assert(scenario != NULL);
313  assert(childnum >= 0 && childnum < scenario->nchildren);
314 
315  return scenario->children[childnum];
316 }
317 
318 /** returns the parent of a scenario */
319 static
321  STOSCENARIO* scenario /**< the scenario */
322  )
323 {
324  assert(scenario != NULL);
325 
326  return scenario->parent;
327 }
328 
329 /** sets the stage name */
330 static
332  SCIP* scip, /**< the SCIP data structure */
333  STOSCENARIO* scenario, /**< the scenario */
334  const char* stagename /**< the stage name */
335  )
336 {
337  assert(scip != NULL);
338  assert(scenario != NULL);
339 
340  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &scenario->stagename, stagename, strlen(stagename) + 1) );
341 
342  return SCIP_OKAY;
343 }
344 
345 /** returns the stage name */
346 static
348  SCIP* scip, /**< the SCIP data structure */
349  STOSCENARIO* scenario /**< the scenario */
350  )
351 {
352  assert(scip != NULL);
353  assert(scenario != NULL);
354 
355  return scenario->stagename;
356 }
357 
358 /** sets the stage num */
359 static
361  SCIP* scip, /**< the SCIP data structure */
362  STOSCENARIO* scenario, /**< the scenario */
363  int stagenum /**< the stage num */
364  )
365 {
366  assert(scip != NULL);
367  assert(scenario != NULL);
368 
369  scenario->stagenum = stagenum;
370 
371  return SCIP_OKAY;
372 }
373 
374 /** returns the stage num */
375 static
377  SCIP* scip, /**< the SCIP data structure */
378  STOSCENARIO* scenario /**< the scenario */
379  )
380 {
381  assert(scip != NULL);
382  assert(scenario != NULL);
383 
384  return scenario->stagenum;
385 }
386 
387 /** sets the scenario name */
388 static
390  SCIP* scip, /**< the SCIP data structure */
391  STOSCENARIO* scenario, /**< the scenario */
392  const char* name /**< the scenario name */
393  )
394 {
395  assert(scip != NULL);
396  assert(scenario != NULL);
397 
398  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &scenario->name, name, strlen(name) + 1) );
399 
400  return SCIP_OKAY;
401 }
402 
403 /** returns the scenario name */
404 static
405 const char* getScenarioName(
406  STOSCENARIO* scenario /**< the scenario */
407  )
408 {
409  assert(scenario != NULL);
410 
411  return scenario->name;
412 }
413 
414 /** sets the scenario num */
415 static
417  SCIP* scip, /**< the SCIP data structure */
418  STOSCENARIO* scenario, /**< the scenario */
419  int scenarionum /**< the scenario num */
420  )
421 {
422  assert(scip != NULL);
423  assert(scenario != NULL);
424 
425  scenario->scenarionum = scenarionum;
426 
427  return SCIP_OKAY;
428 }
429 
430 /** returns the scenario num */
431 static
433  SCIP* scip, /**< the SCIP data structure */
434  STOSCENARIO* scenario /**< the scenario */
435  )
436 {
437  assert(scip != NULL);
438  assert(scenario != NULL);
439 
440  return scenario->scenarionum;
441 }
442 
443 /** sets the scenario probability */
444 static
446  SCIP* scip, /**< the SCIP data structure */
447  STOSCENARIO* scenario, /**< the scenario */
448  SCIP_Real probability /**< the scenario probability */
449  )
450 {
451  assert(scip != NULL);
452  assert(scenario != NULL);
453 
454  scenario->probability = probability;
455 
456  return SCIP_OKAY;
457 }
458 
459 /** returns the scenario probability */
460 static
462  SCIP* scip, /**< the SCIP data structure */
463  STOSCENARIO* scenario /**< the scenario */
464  )
465 {
466  assert(scip != NULL);
467  assert(scenario != NULL);
468 
469  return scenario->probability;
470 }
471 
472 /** add scenario entry */
473 static
475  SCIP* scip, /**< the SCIP data structure */
476  STOSCENARIO* scenario, /**< the scenario */
477  const char* rowname, /**< the row name for the entry */
478  const char* colname, /**< the col name for the entry */
479  SCIP_Real value /**< the value for the entry */
480  )
481 {
482  assert(scip != NULL);
483  assert(scenario != NULL);
484 
485  if( scenario->nentries + 1 > scenario->entriessize )
486  {
487  int newsize;
488  newsize = SCIPcalcMemGrowSize(scip, scenario->nentries + 1);
489  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &scenario->rownames, scenario->entriessize, newsize) );
490  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &scenario->colnames, scenario->entriessize, newsize) );
491  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &scenario->values, scenario->entriessize, newsize) );
492  scenario->entriessize = newsize;
493  }
494 
495  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &scenario->rownames[scenario->nentries], rowname, strlen(rowname) + 1) ); /*lint !e866*/
496  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &scenario->colnames[scenario->nentries], colname, strlen(colname) + 1) ); /*lint !e866*/
497 
498  scenario->values[scenario->nentries] = value;
499  scenario->nentries++;
500 
501  return SCIP_OKAY;
502 }
503 
504 /** returns the number of entries for a scenario */
505 static
507  STOSCENARIO* scenario /**< the scenario */
508  )
509 {
510  assert(scenario != NULL);
511 
512  return scenario->nentries;
513 }
514 
515 /** returns an entry row for a scenario */
516 static
518  STOSCENARIO* scenario, /**< the scenario */
519  int entry /**< the entry number */
520  )
521 {
522  assert(scenario != NULL);
523  assert(entry >= 0 && entry < scenario->nentries);
524 
525  return scenario->rownames[entry];
526 }
527 
528 /** returns an entry column for a scenario */
529 static
531  STOSCENARIO* scenario, /**< the scenario */
532  int entry /**< the entry number */
533  )
534 {
535  assert(scenario != NULL);
536  assert(entry >= 0 && entry < scenario->nentries);
537 
538  return scenario->colnames[entry];
539 }
540 
541 /** returns an entry value for a scenario */
542 static
544  STOSCENARIO* scenario, /**< the scenario */
545  int entry /**< the entry number */
546  )
547 {
548  assert(scenario != NULL);
549  assert(entry >= 0 && entry < scenario->nentries);
550 
551  return scenario->values[entry];
552 }
553 
554 /** copies a scenario.
555  * In the case of blocks, the scenarios must be combined
556  */
557 static
559  SCIP* scip, /**< the SCIP data structure */
560  STOSCENARIO* sourcescenario, /**< the source scenario */
561  STOSCENARIO** targetscenario, /**< the target scenario */
562  SCIP_Bool copyname /**< should the name be copied? */
563  )
564 {
565  SCIP_Real probability;
566  int i;
567 
568  assert(scip != NULL);
569  assert(sourcescenario != NULL);
570  assert(targetscenario != NULL);
571 
572  /* setting the stage name */
573  if( copyname )
574  {
575  SCIP_CALL( setScenarioName(scip, (*targetscenario), sourcescenario->name) );
576  SCIP_CALL( setScenarioStageName(scip, (*targetscenario), sourcescenario->stagename) );
577  SCIP_CALL( setScenarioNum(scip, (*targetscenario), sourcescenario->scenarionum) );
578  SCIP_CALL( setScenarioStageNum(scip, (*targetscenario), sourcescenario->stagenum) );
579  }
580 
581  /* adding the entries from scenario 1 and 2 to the merged scenario */
582  for( i = 0; i < sourcescenario->nentries; i++ )
583  SCIP_CALL( addScenarioEntry(scip, (*targetscenario), sourcescenario->rownames[i], sourcescenario->colnames[i],
584  sourcescenario->values[i]) );
585 
586  /* setting the scenario probability */
587  probability = getScenarioProbability(scip, sourcescenario);
588  SCIP_CALL( setScenarioProbability(scip, (*targetscenario), probability) );
589 
590  return SCIP_OKAY;
591 }
592 
593 /** merge scenarios.
594  * In the case of blocks, the scenarios must be combined
595  */
596 static
598  SCIP* scip, /**< the SCIP data structure */
599  STOSCENARIO* scenario1, /**< the first scenario */
600  STOSCENARIO** mergedscenario /**< the merged scenario */
601  )
602 {
603  SCIP_Real probability;
604  int i;
605 
606  assert(scip != NULL);
607  assert(scenario1 != NULL);
608  assert(mergedscenario != NULL);
609 
610  /* adding the entries from scenario 1 and 2 to the merged scenario */
611  for( i = 0; i < scenario1->nentries; i++ )
612  SCIP_CALL( addScenarioEntry(scip, (*mergedscenario), scenario1->rownames[i], scenario1->colnames[i],
613  scenario1->values[i]) );
614 
615  /* setting the scenario probability */
616  probability = getScenarioProbability(scip, scenario1)*getScenarioProbability(scip, (*mergedscenario));
617  SCIP_CALL( setScenarioProbability(scip, (*mergedscenario), probability) );
618 
619  return SCIP_OKAY;
620 }
621 
622 /** adds a child to a given scenario */
623 static
625  SCIP* scip, /**< the SCIP data structure */
626  STOSCENARIO** parent, /**< the parent scenario */
627  STOSCENARIO* child /**< the child scenario */
628  )
629 {
630  STOSCENARIO* scenario;
631 
632  assert(parent != NULL);
633  assert((*parent) != NULL);
634  assert(child != NULL);
635 
636  if( (*parent)->nchildren + 1 > (*parent)->childrensize )
637  SCIP_CALL( SCIPensureBlockMemoryArray(scip, &(*parent)->children, &(*parent)->childrensize,
638  (*parent)->nchildren + 1) );
639 
640  SCIP_CALL( createScenarioData(scip, &scenario) );
641  SCIP_CALL( copyScenario(scip, child, &scenario, TRUE) );
642  scenario->parent = (*parent);
643 
644  (*parent)->children[(*parent)->nchildren] = scenario;
645  (*parent)->nchildren++;
646 
647  return SCIP_OKAY;
648 }
649 
650 /** recursively adds the scenarios to the reader data */
651 static
653  SCIP* scip, /**< the SCIP data structure */
654  STOSCENARIO** scenariotree, /**< the scenario tree */
655  STOSCENARIO*** scenarios, /**< the array of scenarios */
656  int* numscenarios, /**< the number of scenarios per stage */
657  int numstages, /**< the number of stages */
658  int stage /**< the number of the stage. Also the depth of the tree */
659  )
660 {
661  int stageindex;
662  int i;
663 
664  assert(scip != NULL);
665  assert(scenariotree != NULL);
666  assert(stage >= 0 && stage < numstages);
667 
668  /* finding the scenarios for this stage */
669  for( i = 0; i < numstages; i++ )
670  {
671  if( strcmp(getScenarioStageName(scip, scenarios[i][0]), SCIPtimGetStageName(scip, stage + 1)) == 0 )
672  break;
673  }
674  assert(i < numstages);
675 
676  stageindex = i;
677 
678  /* adds each scenario to the scenario tree */
679  for( i = 0; i < numscenarios[stageindex]; i++ )
680  {
681  /* adding child to the scenario tree */
682  SCIP_CALL( scenarioAddChild(scip, scenariotree, scenarios[stageindex][i]) );
683 
684  /* building the tree below the recently added child */
685  if( stage < numstages - 1 )
686  {
687  STOSCENARIO* child = getScenarioChild((*scenariotree), getScenarioNChildren((*scenariotree)) - 1);
688  SCIP_CALL( buildScenarioTree(scip, &child, scenarios, numscenarios, numstages, stage + 1) );
689  }
690  }
691 
692  return SCIP_OKAY;
693 }
694 
695 
696 /* adds the scenarios to the reader data */
697 static
699  SCIP* scip, /**< the SCIP data structure */
700  SCIP_READERDATA* readerdata, /**< the reader data */
701  STOSCENARIO*** scenarios, /**< the array of scenarios */
702  int* numscenarios, /**< the number of scenarios per stage */
703  int numscenariostages /**< the number of stages for which scenarios were collected */
704  )
705 {
706  int numstages; /* the number of stages */
707  int i;
708 
709  assert(scip != NULL);
710  assert(readerdata != NULL);
711  assert(scenarios != NULL);
712 
713  numstages = SCIPtimGetNStages(scip);
714  if( numstages != numscenariostages + 1 )
715  assert(FALSE);
716 
717  SCIP_CALL( buildScenarioTree(scip, &readerdata->scenariotree, scenarios, numscenarios, numscenariostages, 0) );
718 
719  /* setting the number of scenarios per stage in the TIME reader data */
720  for( i = 0; i < numscenariostages; i++ )
721  readerdata->numscenarios += numscenarios[i];
722 
723  return SCIP_OKAY;
724 }
725 
726 
727 /** finds a scenario with a given name */
728 static
730  STOSCENARIO* scenariotree, /**< the scenario tree to search */
731  const char* scenname /**< the name of the scenario to search */
732  )
733 {
734  STOSCENARIO* retscen;
735  int i;
736 
737  if( strcmp(getScenarioName(scenariotree), scenname) == 0 )
738  return scenariotree;
739  else
740  {
741  retscen = NULL;
742  for( i = 0; i < getScenarioNChildren(scenariotree); i++ )
743  {
744  retscen = findScenarioInTree(scenariotree->children[i], scenname);
745  if( retscen != NULL )
746  return retscen;
747  }
748  }
749 
750  return NULL;
751 }
752 
753 
754 /** inserts a scenario into the reader data scenario tree */
755 static
757  SCIP* scip, /**< the SCIP data structure */
758  SCIP_READERDATA* readerdata, /**< the reader data */
759  STOSCENARIO* scenario, /**< the scenario to insert in the scenario tree */
760  char* parentname /**< the parent scenario for the inserting scenario */
761  )
762 {
763  STOSCENARIO* parentscen;
764 
765  assert(scip != NULL);
766  assert(readerdata != NULL);
767  assert(scenario != NULL);
768 
769  /* searching for the parent scenario in the tree */
770  parentscen = findScenarioInTree(readerdata->scenariotree, parentname);
771 
772  /* adding the scenario as a child of the parent scenario */
773  SCIP_CALL( scenarioAddChild(scip, &parentscen, scenario) );
774 
775  readerdata->numscenarios++;
776 
777  return SCIP_OKAY;
778 }
779 
780 
781 /* builds the scenarios from the blocks for a given stage */
782 static
784  SCIP* scip, /**< the SCIP data structure */
785  STOSCENARIO*** blocks, /**< the block that form the scenarios */
786  STOSCENARIO*** scenarios, /**< the array to store the scenarios */
787  STOSCENARIO*** blocksforscen, /**< the blocks that will form the scenario */
788  int* numblocksforscen, /**< the number of blocks that form the scenario */
789  int numblocks, /**< the number of blocks */
790  int* numblocksperblock, /**< the number of blocks for a given block */
791  int* numscenarios, /**< the number of scenarios */
792  int* scenariossize, /**< the size of scenarios array */
793  const char* stage, /**< the stage for this scenario */
794  int stagenum, /**< the number of the stage */
795  int blocknum /**< the block number */
796  )
797 {
798  SCIP_Bool processed;
799  int i;
800  int j;
801 
802  assert(scip != NULL);
803  assert(blocks != NULL);
804  assert(scenarios != NULL);
805  assert(blocksforscen != NULL);
806 
807  processed = FALSE;
808  i = blocknum + 1;
809  while( !processed && i < numblocks )
810  {
811  /* it is only necessary to process the next block in the list the belongs to the given stage. */
812  if( strcmp(getScenarioStageName(scip, blocks[i][0]), stage) == 0 )
813  {
814  processed = TRUE;
815 
816  for( j = 0; j < numblocksperblock[i]; j++ )
817  {
818  /* adding the blocks that will build the scenario */
819  (*blocksforscen)[(*numblocksforscen)] = blocks[i][j];
820  (*numblocksforscen)++;
821  SCIP_CALL( buildScenariosFromBlocks(scip, blocks, scenarios, blocksforscen, numblocksforscen, numblocks,
822  numblocksperblock, numscenarios, scenariossize, stage, stagenum + 1, i) );
823 
824  /* the last block needs to be removed so that a new block can be used in its place */
825  (*numblocksforscen)--;
826  }
827  }
828  else
829  {
830  /* the index is only incremented if no block is processed. This is necessary because the value of i is used in
831  * the next if statement for identifying whether all blocks have been processed.
832  */
833  i++;
834  }
835  }
836 
837  /* when all blocks have been inspected, then it is possible to build the scenario */
838  if( i == numblocks )
839  {
840  char scenarioname[SCIP_MAXSTRLEN];
841 
842  /* ensuring the correct amount of memory is available */
843  if( (*numscenarios) + 1 > (*scenariossize) )
844  {
845  int newsize;
846  newsize = SCIPcalcMemGrowSize(scip, (*numscenarios) + 1);
847  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, scenarios, (*scenariossize), newsize) );
848  (*scenariossize) = newsize;
849  }
850 
851  SCIP_CALL( createScenarioData(scip, &(*scenarios)[(*numscenarios)]) );
852 
853  /* setting the scenario name */
854  (void) SCIPsnprintf(scenarioname, SCIP_MAXSTRLEN, "Scenario_%s_%d", stage, (*numscenarios));
855  SCIP_CALL( setScenarioName(scip, (*scenarios)[(*numscenarios)], scenarioname) );
856  SCIP_CALL( setScenarioStageName(scip, (*scenarios)[(*numscenarios)], stage) );
857  SCIP_CALL( setScenarioNum(scip, (*scenarios)[(*numscenarios)], (*numscenarios)) );
858  SCIP_CALL( setScenarioStageNum(scip, (*scenarios)[(*numscenarios)], stagenum) );
859 
860  /* if there is only a single block for the scenario, then we simply copy the block.
861  * Otherwise, the blocks are merged into a single scenario */
862  if( (*numblocksforscen) == 1 )
863  SCIP_CALL( copyScenario(scip, (*blocksforscen)[0], &(*scenarios)[(*numscenarios)], FALSE) );
864  else
865  {
866  SCIP_CALL( copyScenario(scip, (*blocksforscen)[0], &(*scenarios)[(*numscenarios)], FALSE) );
867  for( i = 1; i < (*numblocksforscen); i++ )
868  SCIP_CALL( mergeScenarios(scip, (*blocksforscen)[i], &(*scenarios)[(*numscenarios)]) );
869  }
870 
871  (*numscenarios)++;
872  }
873 
874  return SCIP_OKAY;
875 }
876 
877 
878 /* creates the scenarios from the blocks */
879 static
881  SCIP* scip, /**< the SCIP data structure */
882  SCIP_READERDATA* readerdata, /**< the reader data */
883  STOSCENARIO*** blocks, /**< the block that form the scenarios */
884  int numblocks, /**< the number of blocks */
885  int* numblocksperblock, /**< the number of blocks for each block type */
886  int numstages /**< the number of stages */
887  )
888 {
889  STOSCENARIO*** scenarios;
890  STOSCENARIO** blocksforscen;
891  int* numscenarios;
892  int* scenariossize;
893  int numblocksforscen;
894  int stagenum;
895  char periods[SCIP_MAXSTRLEN];
896  int i;
897  int j;
898 
899  assert(scip != NULL);
900  assert(blocks != NULL);
901 
902  /* allocating the memory for the scenarios array */
903  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &scenarios, numstages) );
904  SCIP_CALL( SCIPallocBufferArray(scip, &numscenarios, numstages) );
905  SCIP_CALL( SCIPallocBufferArray(scip, &scenariossize, numstages) );
906  for( i = 0; i < numstages; i++ )
907  {
908  scenariossize[i] = STO_DEFAULT_BLOCKARRAYSIZE;
909  numscenarios[i] = 0;
910  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &scenarios[i], scenariossize[i]) );
911  }
912 
913  /* allocating the memory for the block for scenario array */
914  SCIP_CALL( SCIPallocBufferArray(scip, &blocksforscen, numblocks) );
915 
916  (void) SCIPsnprintf(periods, SCIP_MAXSTRLEN, "");
917 
918  stagenum = 0;
919  for( i = 0; i < numblocks; i++ )
920  {
921  numblocksforscen = 0;
922  if( strstr(periods, getScenarioStageName(scip, blocks[i][0])) == NULL )
923  {
924  /* recording the stage name as processed */
925  (void) SCIPsnprintf(periods, SCIP_MAXSTRLEN, "%s_%s", periods, getScenarioStageName(scip, blocks[i][0]));
926 
927  SCIP_CALL( buildScenariosFromBlocks(scip, blocks, &scenarios[stagenum], &blocksforscen, &numblocksforscen,
928  numblocks, numblocksperblock, &numscenarios[stagenum], &scenariossize[stagenum],
929  getScenarioStageName(scip, blocks[i][0]), stagenum, i - 1) );
930 
931  stagenum++;
932  }
933  }
934 
935  /* adding the scenarios to the reader data */
936  SCIP_CALL( setScenarioNum(scip, readerdata->scenariotree, 0) );
937  SCIP_CALL( setScenarioStageNum(scip, readerdata->scenariotree, 0) );
938  SCIP_CALL( addScenariosToReaderdata(scip, readerdata, scenarios, numscenarios, numstages) );
939 
940  SCIPfreeBufferArray(scip, &blocksforscen);
941  for( i = numstages - 1; i >= 0; i-- )
942  {
943  for( j = numscenarios[i] - 1; j >= 0; j-- )
944  SCIP_CALL( freeScenarioTree(scip, &scenarios[i][j]) );
945  SCIPfreeBlockMemoryArray(scip, &scenarios[i], scenariossize[i]);
946  }
947  SCIPfreeBufferArray(scip, &scenariossize);
948  SCIPfreeBufferArray(scip, &numscenarios);
949  SCIPfreeBlockMemoryArray(scip, &scenarios, numstages);
950 
951  return SCIP_OKAY;
952 }
953 
954 /** creates the reader data */
955 static
957  SCIP* scip, /**< SCIP data structure */
958  SCIP_READERDATA* readerdata /**< the reader data */
959  )
960 {
961  assert(scip != NULL);
962  assert(readerdata != NULL);
963 
964  /* creating the initial scenario */
965  SCIP_CALL( createScenarioData(scip, &readerdata->scenariotree) );
966 
967  /* setting the scenario name and stage name */
968  SCIP_CALL( setScenarioName(scip, readerdata->scenariotree, "ROOT") );
969  SCIP_CALL( setScenarioStageName(scip, readerdata->scenariotree, SCIPtimGetStageName(scip, 0)) );
970 
971  return SCIP_OKAY;
972 }
973 
974 /** frees the reader data */
975 static
977  SCIP* scip, /**< the SCIP data structure */
978  SCIP_READERDATA* readerdata /**< the reader data */
979  )
980 {
981  assert(scip != NULL);
982  assert(readerdata != NULL);
983 
984  /* freeing the scenario tree */
985  if( readerdata->scenariotree != NULL )
986  SCIP_CALL( freeScenarioTree(scip, &readerdata->scenariotree) );
987 
988  SCIPfreeBlockMemory(scip, &readerdata);
989 
990  return SCIP_OKAY;
991 }
992 
993 /** creates the sto input structure */
994 static
996  SCIP* scip, /**< SCIP data structure */
997  STOINPUT** stoi, /**< sto input structure */
998  SCIP_FILE* fp /**< file object for the input file */
999  )
1000 {
1001  assert(stoi != NULL);
1002  assert(fp != NULL);
1003 
1004  SCIP_CALL( SCIPallocBlockMemory(scip, stoi) );
1005 
1006  (*stoi)->section = STO_STOCH;
1007  (*stoi)->stochinfotype = STO_STOCHINFO_NONE;
1008  (*stoi)->fp = fp;
1009  (*stoi)->lineno = 0;
1010  (*stoi)->haserror = FALSE;
1011  (*stoi)->buf [0] = '\0';
1012  (*stoi)->probname[0] = '\0';
1013  (*stoi)->stochtype[0] = '\0';
1014  (*stoi)->f0 = NULL;
1015  (*stoi)->f1 = NULL;
1016  (*stoi)->f2 = NULL;
1017  (*stoi)->f3 = NULL;
1018  (*stoi)->f4 = NULL;
1019  (*stoi)->f5 = NULL;
1020 
1021  return SCIP_OKAY;
1022 }
1023 
1024 /** free the sto input structure */
1025 static
1027  SCIP* scip, /**< SCIP data structure */
1028  STOINPUT** stoi /**< sto input structure */
1029  )
1030 {
1031  SCIPfreeBlockMemory(scip, stoi);
1032 }
1033 
1034 /** returns the current section */
1035 static
1037  const STOINPUT* stoi /**< sto input structure */
1038  )
1039 {
1040  assert(stoi != NULL);
1041 
1042  return stoi->section;
1043 }
1044 
1045 /** returns the stochastic information type */
1046 static
1048  const STOINPUT* stoi /**< sto input structure */
1049  )
1050 {
1051  assert(stoi != NULL);
1052 
1053  return stoi->stochinfotype;
1054 }
1055 
1056 /** return the current value of field 0 */
1057 static
1058 const char* stoinputField0(
1059  const STOINPUT* stoi /**< sto input structure */
1060  )
1061 {
1062  assert(stoi != NULL);
1063 
1064  return stoi->f0;
1065 }
1066 
1067 /** return the current value of field 1 */
1068 static
1069 const char* stoinputField1(
1070  const STOINPUT* stoi /**< sto input structure */
1071  )
1072 {
1073  assert(stoi != NULL);
1074 
1075  return stoi->f1;
1076 }
1077 
1078 /** return the current value of field 2 */
1079 static
1080 const char* stoinputField2(
1081  const STOINPUT* stoi /**< sto input structure */
1082  )
1083 {
1084  assert(stoi != NULL);
1085 
1086  return stoi->f2;
1087 }
1088 
1089 /** return the current value of field 3 */
1090 static
1091 const char* stoinputField3(
1092  const STOINPUT* stoi /**< sto input structure */
1093  )
1094 {
1095  assert(stoi != NULL);
1096 
1097  return stoi->f3;
1098 }
1099 
1100 /** return the current value of field 4 */
1101 static
1102 const char* stoinputField4(
1103  const STOINPUT* stoi /**< sto input structure */
1104  )
1105 {
1106  assert(stoi != NULL);
1107 
1108  return stoi->f4;
1109 }
1110 
1111 /** return the current value of field 5 */
1112 static
1113 const char* stoinputField5(
1114  const STOINPUT* stoi /**< sto input structure */
1115  )
1116 {
1117  assert(stoi != NULL);
1118 
1119  return stoi->f5;
1120 }
1121 
1122 /** returns if an error was detected */
1123 static
1125  const STOINPUT* stoi /**< sto input structure */
1126  )
1127 {
1128  assert(stoi != NULL);
1129 
1130  return stoi->haserror;
1131 }
1132 
1133 /** set the section in the sto input structure to given section */
1134 static
1136  STOINPUT* stoi, /**< sto input structure */
1137  STOSECTION section /**< section that is set */
1138  )
1139 {
1140  assert(stoi != NULL);
1141 
1142  stoi->section = section;
1143 }
1144 
1145 /** set the stochastic info type in the sto input structure */
1146 static
1148  STOINPUT* stoi, /**< sto input structure */
1149  STOSTOCHINFO stochinfotype /**< the stochastic infomation type */
1150  )
1151 {
1152  assert(stoi != NULL);
1153 
1154  stoi->stochinfotype = stochinfotype;
1155 }
1156 
1157 /** set the problem name in the sto input structure to given problem name */
1158 static
1160  STOINPUT* stoi, /**< sto input structure */
1161  const char* probname /**< name of the problem to set */
1162  )
1163 {
1164  assert(stoi != NULL);
1165  assert(probname != NULL);
1166  assert(strlen(probname) < sizeof(stoi->probname));
1167 
1168  (void)SCIPmemccpy(stoi->probname, probname, '\0', STO_MAX_NAMELEN - 1);
1169 }
1170 
1171 /** set the type name in the sto input structure to given objective name */
1172 static
1174  STOINPUT* stoi, /**< sto input structure */
1175  const char* stochtype /**< name of the scenario type */
1176  )
1177 {
1178  assert(stoi != NULL);
1179  assert(stochtype != NULL);
1180  assert(strlen(stochtype) < sizeof(stoi->stochtype));
1181 
1182  (void)SCIPmemccpy(stoi->stochtype, stochtype, '\0', STO_MAX_NAMELEN - 1);
1183 }
1184 
1185 static
1187  STOINPUT* stoi /**< sto input structure */
1188  )
1189 {
1190  assert(stoi != NULL);
1191 
1192  SCIPerrorMessage("Syntax error in line %d\n", stoi->lineno);
1193  stoi->section = STO_ENDATA;
1194  stoi->haserror = TRUE;
1195 }
1196 
1197 /** fill the line from \p pos up to column 80 with blanks. */
1198 static
1200  char* buf, /**< buffer to clear */
1201  unsigned int pos /**< position to start the clearing process */
1202  )
1203 {
1204  unsigned int i;
1205 
1206  for(i = pos; i < 80; i++)
1207  buf[i] = BLANK;
1208  buf[80] = '\0';
1209 }
1210 
1211 /** read a sto format data line and parse the fields. */
1212 static
1214  STOINPUT* stoi /**< sto input structure */
1215  )
1216 {
1217  unsigned int len;
1218  unsigned int i;
1219  char* s;
1220  SCIP_Bool is_marker;
1221  SCIP_Bool is_empty;
1222  char* nexttok;
1223 
1224  do
1225  {
1226  stoi->f0 = stoi->f1 = stoi->f2 = stoi->f3 = stoi->f4 = stoi->f5 = 0;
1227  is_marker = FALSE;
1228 
1229  /* Read until we have not a comment line. */
1230  do
1231  {
1232  stoi->buf[STO_MAX_LINELEN-1] = '\0';
1233  if( NULL == SCIPfgets(stoi->buf, (int) sizeof(stoi->buf), stoi->fp) )
1234  return FALSE;
1235  stoi->lineno++;
1236  }
1237  while( *stoi->buf == '*' );
1238 
1239  /* Normalize line */
1240  len = (unsigned int) strlen(stoi->buf);
1241 
1242  for( i = 0; i < len; i++ )
1243  {
1244  if( (stoi->buf[i] == '\t') || (stoi->buf[i] == '\n') || (stoi->buf[i] == '\r') )
1245  stoi->buf[i] = BLANK;
1246  }
1247 
1248  if( len < 80 )
1249  clearFrom(stoi->buf, len);
1250 
1251  SCIPdebugMessage("line %d: <%s>\n", stoi->lineno, stoi->buf);
1252 
1253  assert(strlen(stoi->buf) >= 80);
1254 
1255  /* Look for new section */
1256  if( *stoi->buf != BLANK )
1257  {
1258  stoi->f0 = SCIPstrtok(&stoi->buf[0], " ", &nexttok);
1259 
1260  assert(stoi->f0 != 0);
1261 
1262  stoi->f1 = SCIPstrtok(NULL, " ", &nexttok);
1263 
1264  return TRUE;
1265  }
1266 
1267  s = &stoi->buf[1];
1268 
1269  /* At this point it is not clear if we have a indicator field.
1270  * If there is none (e.g. empty) f1 will be the first name field.
1271  * If there is one, f2 will be the first name field.
1272  *
1273  * Initially comment marks '$' are only allowed in the beginning
1274  * of the 2nd and 3rd name field. We test all fields but the first.
1275  * This makes no difference, since if the $ is at the start of a value
1276  * field, the line will be erroneous anyway.
1277  */
1278  do
1279  {
1280  if( NULL == (stoi->f1 = SCIPstrtok(s, " ", &nexttok)) )
1281  break;
1282 
1283  if( (NULL == (stoi->f2 = SCIPstrtok(NULL, " ", &nexttok))) || (*stoi->f2 == '$') )
1284  {
1285  stoi->f2 = 0;
1286  break;
1287  }
1288 
1289  if( (NULL == (stoi->f3 = SCIPstrtok(NULL, " ", &nexttok))) || (*stoi->f3 == '$') )
1290  {
1291  stoi->f3 = 0;
1292  break;
1293  }
1294 
1295  if( (NULL == (stoi->f4 = SCIPstrtok(NULL, " ", &nexttok))) || (*stoi->f4 == '$') )
1296  {
1297  stoi->f4 = 0;
1298  break;
1299  }
1300 
1301  if( (NULL == (stoi->f5 = SCIPstrtok(NULL, " ", &nexttok))) || (*stoi->f5 == '$') )
1302  stoi->f5 = 0;
1303  }
1304  while( FALSE );
1305 
1306  /* check for empty lines */
1307  is_empty = (stoi->f0 == NULL && stoi->f1 == NULL);
1308  }
1309  while( is_marker || is_empty );
1310 
1311  return TRUE;
1312 }
1313 
1314 /** Process STOCH section. */
1315 static
1317  SCIP* scip, /**< SCIP data structure */
1318  STOINPUT* stoi /**< sto input structure */
1319  )
1320 {
1321  assert(stoi != NULL);
1322 
1323  SCIPdebugMsg(scip, "read problem name\n");
1324 
1325  /* This has to be the Line with the NAME section. */
1326  if( !stoinputReadLine(stoi) || stoinputField0(stoi) == NULL || strcmp(stoinputField0(stoi), "STOCH") )
1327  {
1328  stoinputSyntaxerror(stoi);
1329  return SCIP_OKAY;
1330  }
1331 
1332  /* Sometimes the name is omitted. */
1333  stoinputSetProbname(stoi, (stoinputField1(stoi) == 0) ? "_STO_" : stoinputField1(stoi));
1334 
1335  /* This hat to be a new section */
1336  if( !stoinputReadLine(stoi) || (stoinputField0(stoi) == NULL) )
1337  {
1338  stoinputSyntaxerror(stoi);
1339  return SCIP_OKAY;
1340  }
1341 
1342  /* setting the stochatic information section */
1343  if( !strncmp(stoinputField0(stoi), "BLOCKS", 6) )
1345  else if( !strncmp(stoinputField0(stoi), "SCENARIOS", 9) )
1347  else if( !strncmp(stoinputField0(stoi), "INDEP", 5) )
1349  else
1350  {
1351  stoinputSyntaxerror(stoi);
1352  return SCIP_OKAY;
1353  }
1354 
1355  /* setting the stochastic information type */
1356  if( !strncmp(stoinputField1(stoi), "DISCRETE", 8) )
1358  else if( !strncmp(stoinputField1(stoi), "UNIFORM", 7) )
1360  else if( !strncmp(stoinputField1(stoi), "NORMAL", 6) )
1362  else if( !strncmp(stoinputField1(stoi), "SUB", 3) )
1364  else if( !strncmp(stoinputField1(stoi), "LINTR", 5) )
1366  else
1367  {
1368  stoinputSyntaxerror(stoi);
1369  return SCIP_OKAY;
1370  }
1371 
1372  return SCIP_OKAY;
1373 }
1374 
1375 /** Process BLOCKS section. */
1376 static
1378  STOINPUT* stoi, /**< sto input structure */
1379  SCIP* scip, /**< SCIP data structure */
1380  SCIP_READERDATA* readerdata /**< the reader data */
1381  )
1382 {
1383  STOSCENARIO*** blocks;
1384  int numblocks;
1385  int* numblocksperblock;
1386  int blockssize;
1387  int* blocksperblocksize;
1388  char BL[] = "BL";
1389  int blocknum;
1390  int blockindex;
1391  int i;
1392  int j;
1393  char stagenames[SCIP_MAXSTRLEN];
1394  int numstages;
1395 
1396  SCIPdebugMsg(scip, "read Blocks\n");
1397 
1398  /* This has to be the Line with the name. */
1399  if( stoinputField1(stoi) == NULL )
1400  {
1401  stoinputSyntaxerror(stoi);
1402  return SCIP_OKAY;
1403  }
1404 
1405  stoinputSetStochtype(stoi, stoinputField1(stoi));
1406 
1407  /* initializing the block data */
1408  numblocks = 0;
1409  blockssize = STO_DEFAULT_ARRAYSIZE;
1411  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &numblocksperblock, STO_DEFAULT_ARRAYSIZE) );
1412  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &blocksperblocksize, STO_DEFAULT_ARRAYSIZE) );
1413 
1414  blockindex = 0;
1415  blocknum = 0;
1416 
1417  /* initializing the stage names record */
1418  numstages = 0;
1419  (void) SCIPsnprintf(stagenames, SCIP_MAXSTRLEN, "");
1420 
1421  while( stoinputReadLine(stoi) )
1422  {
1423  if( stoinputField0(stoi) != NULL )
1424  {
1425  if( !strcmp(stoinputField0(stoi), "BLOCKS") )
1426  {
1428  if( strcmp(stoinputField1(stoi), "DISCRETE") )
1429  {
1430  SCIPerrorMessage("Sorry, %s blocks stucture is not currently supported.\n", stoinputField1(stoi));
1431  SCIPerrorMessage("Only DISCRETE blocks are supported.\n");
1432  goto TERMINATE;
1433  }
1434  }
1435  else if( !strcmp(stoinputField0(stoi), "ENDATA") )
1436  {
1437  SCIP_CALL( createScenariosFromBlocks(scip, readerdata, blocks, numblocks, numblocksperblock, numstages) );
1439  }
1440  else
1441  stoinputSyntaxerror(stoi);
1442 
1443  goto TERMINATE;
1444  }
1445 
1446  if( strcmp(stoinputField1(stoi), BL) == 0 )
1447  {
1448  SCIP_Bool foundblock = FALSE;
1449 
1450  /* checking whether the stage has been added previously */
1451  if( strstr(stagenames, stoinputField3(stoi)) == NULL )
1452  {
1453  /* recording the stage name as processed */
1454  (void) SCIPsnprintf(stagenames, SCIP_MAXSTRLEN, "%s_%s", stagenames, stoinputField3(stoi));
1455  numstages++;
1456  }
1457 
1458  /* determining whether a block name has previously been added */
1459  for( i = 0; i < numblocks; i++ )
1460  {
1461  if( strcmp(getScenarioName(blocks[i][0]), stoinputField2(stoi)) == 0 )
1462  {
1463  foundblock = TRUE;
1464  break;
1465  }
1466  }
1467  blocknum = i;
1468 
1469  /* if the block is found, then the memory for the blocks array must be ensured */
1470  if( foundblock )
1471  {
1472  /* ensuring enough memory is available for the blocks */
1473  if( numblocksperblock[blocknum] + 1 > blocksperblocksize[blocknum] )
1474  {
1475  int newsize;
1476  newsize = SCIPcalcMemGrowSize(scip, numblocksperblock[blocknum] + 1);
1477  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &blocks[blocknum], blocksperblocksize[blocknum], newsize) ); /*lint !e866*/
1478  blocksperblocksize[blocknum] = newsize;
1479  }
1480  }
1481  else
1482  {
1483  /* ensuring enough memory is available for the blocks */
1484  if( numblocks + 1 > blockssize )
1485  {
1486  int newsize;
1487  newsize = SCIPcalcMemGrowSize(scip, numblocks + 1);
1488  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &blocks, blockssize, newsize) );
1489  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &numblocksperblock, blockssize, newsize) );
1490  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &blocksperblocksize, blockssize, newsize) );
1491  blockssize = newsize;
1492  }
1493 
1494  blocksperblocksize[blocknum] = STO_DEFAULT_BLOCKARRAYSIZE;
1495  numblocksperblock[blocknum] = 0;
1496  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &blocks[blocknum], blocksperblocksize[blocknum]) );
1497  }
1498 
1499  blockindex = numblocksperblock[blocknum];
1500 
1501  /* creating the scenario data structure */
1502  SCIP_CALL( createScenarioData(scip, &blocks[blocknum][blockindex]) );
1503 
1504  SCIP_CALL( setScenarioName(scip, blocks[blocknum][blockindex], stoinputField2(stoi)) );
1505  SCIP_CALL( setScenarioStageName(scip, blocks[blocknum][blockindex], stoinputField3(stoi)) );
1506  SCIP_CALL( setScenarioProbability(scip, blocks[blocknum][blockindex], atof(stoinputField4(stoi))) );
1507  numblocksperblock[blocknum]++;
1508 
1509  if( !foundblock )
1510  numblocks++;
1511  }
1512  else
1513  {
1514  SCIP_CALL( addScenarioEntry(scip, blocks[blocknum][blockindex], stoinputField2(stoi), stoinputField1(stoi),
1515  atof(stoinputField3(stoi))) );
1516  }
1517  }
1518  stoinputSyntaxerror(stoi);
1519 
1520 TERMINATE:
1521 
1522  /* releasing the scenario data */
1523  for( i = numblocks - 1; i >= 0; i-- )
1524  {
1525  for( j = numblocksperblock[i] - 1; j >= 0; j-- )
1526  SCIP_CALL( freeScenarioTree(scip, &blocks[i][j]) );
1527  }
1528 
1529  for( i = numblocks - 1; i >= 0; i-- )
1530  SCIPfreeBlockMemoryArray(scip, &blocks[i], blocksperblocksize[i]);
1531  SCIPfreeBlockMemoryArray(scip, &blocksperblocksize, blockssize);
1532  SCIPfreeBlockMemoryArray(scip, &numblocksperblock, blockssize);
1533  SCIPfreeBlockMemoryArray(scip, &blocks, blockssize);
1534 
1535  return SCIP_OKAY;
1536 }
1537 
1538 
1539 /** Process SCENARIOS section. */
1540 static
1542  STOINPUT* stoi, /**< sto input structure */
1543  SCIP* scip, /**< SCIP data structure */
1544  SCIP_READERDATA* readerdata /**< the reader data */
1545  )
1546 {
1547  STOSCENARIO* scenario;
1548  char SC[] = "SC";
1549  char wrongroot[] = "\'ROOT\'";
1550  char parentname[SCIP_MAXSTRLEN];
1551  char scennames[SCIP_MAXSTRLEN];
1552  char tmpname[SCIP_MAXSTRLEN];
1553  int numscenarios;
1554  SCIP_Bool addscenario;
1555 
1556  SCIPdebugMsg(scip, "read SCENARIOS\n");
1557 
1558  /* This has to be the Line with the name. */
1559  if( stoinputField1(stoi) == NULL )
1560  {
1561  stoinputSyntaxerror(stoi);
1562  return SCIP_OKAY;
1563  }
1564 
1565  stoinputSetStochtype(stoi, stoinputField1(stoi));
1566 
1567  /* initializing the scen names record */
1568  numscenarios = 0;
1569  (void) SCIPsnprintf(scennames, SCIP_MAXSTRLEN, "ROOT");
1570 
1571  scenario = NULL;
1572  addscenario = FALSE;
1573 
1574  /* initializing the root scenario in the reader data */
1575  SCIP_CALL( setScenarioNum(scip, readerdata->scenariotree, 0) );
1576  SCIP_CALL( setScenarioStageNum(scip, readerdata->scenariotree, 0) );
1577 
1578  while( stoinputReadLine(stoi) )
1579  {
1580  if( stoinputField0(stoi) != NULL )
1581  {
1582  /* if a scenario has been created that needs to be added to the scenario tree */
1583  if( addscenario )
1584  {
1585  SCIP_CALL( insertScenarioInReaderdata(scip, readerdata, scenario, parentname) );
1586 
1587  /* freeing the scenario */
1588  SCIP_CALL( freeScenarioTree(scip, &scenario) );
1589  }
1590 
1591  if( !strcmp(stoinputField0(stoi), "SCENARIOS") )
1592  {
1594  if( strcmp(stoinputField1(stoi), "DISCRETE") )
1595  {
1596  SCIPerrorMessage("Sorry, %s scenarios is not currently supported.\n", stoinputField1(stoi));
1597  SCIPerrorMessage("Only DISCRETE scenarios are supported.\n");
1598  goto TERMINATE;
1599  }
1600  }
1601  else if( !strcmp(stoinputField0(stoi), "ENDATA") )
1603  else
1604  stoinputSyntaxerror(stoi);
1605 
1606  goto TERMINATE;
1607  }
1608 
1609  if( strcmp(stoinputField1(stoi), SC) == 0 )
1610  {
1611  int stagenum;
1612 
1613  /* if a scenario has been created that needs to be added to the scenario tree */
1614  if( addscenario )
1615  {
1616  SCIP_CALL( insertScenarioInReaderdata(scip, readerdata, scenario, parentname) );
1617 
1618  /* freeing the scenario */
1619  SCIP_CALL( freeScenarioTree(scip, &scenario) );
1620  assert(scenario == NULL);
1621  }
1622 
1623  if( strcmp(wrongroot, stoinputField3(stoi)) == 0 )
1624  (void) SCIPsnprintf(parentname, SCIP_MAXSTRLEN, "%s", "ROOT");
1625  else
1626  (void) SCIPsnprintf(parentname, SCIP_MAXSTRLEN, "%s", stoinputField3(stoi));
1627 
1628  /* checking whether the stage has been added previously */
1629  if( strstr(scennames, stoinputField2(stoi)) == NULL )
1630  {
1631  /* recording the stage name as processed */
1632  (void) SCIPsnprintf(tmpname, SCIP_MAXSTRLEN, "%s_%s", scennames, stoinputField2(stoi));
1633  (void) SCIPsnprintf(scennames, SCIP_MAXSTRLEN, "%s", tmpname);
1634  }
1635 
1636  /* checking whether the "common" scenario has been added yet */
1637  if( strstr(scennames, parentname) == NULL )
1638  {
1639  SCIPerrorMessage("Scenario <%s> needs to be read before scenario <%s>\n", parentname, stoinputField2(stoi));
1640  stoinputSyntaxerror(stoi);
1641  goto TERMINATE;
1642  }
1643 
1644  /* the "common" scenario has been added before, so a child can be added to the scenario tree */
1645  SCIP_CALL( createScenarioData(scip, &scenario) );
1646 
1647  SCIP_CALL( setScenarioName(scip, scenario, stoinputField2(stoi)) );
1648  SCIP_CALL( setScenarioStageName(scip, scenario, stoinputField5(stoi)) );
1649  SCIP_CALL( setScenarioNum(scip, scenario, numscenarios) );
1650 
1651  stagenum = SCIPtimFindStage(scip, stoinputField5(stoi));
1652  if( stagenum < 0 )
1653  {
1654  stoinputSyntaxerror(stoi);
1655  goto TERMINATE;
1656  }
1657  SCIP_CALL( setScenarioStageNum(scip, scenario, stagenum) );
1658  SCIP_CALL( setScenarioProbability(scip, scenario, atof(stoinputField4(stoi))) );
1659 
1660  numscenarios++;
1661  addscenario = TRUE;
1662  }
1663  else if( addscenario )
1664  {
1665  SCIP_CALL( addScenarioEntry(scip, scenario, stoinputField2(stoi), stoinputField1(stoi),
1666  atof(stoinputField3(stoi))) );
1667  }
1668  }
1669  stoinputSyntaxerror(stoi);
1670 
1671 TERMINATE:
1672 
1673  return SCIP_OKAY;
1674 }
1675 
1676 
1677 /** Process INDEP section. */
1678 static
1680  STOINPUT* stoi, /**< sto input structure */
1681  SCIP* scip, /**< SCIP data structure */
1682  SCIP_READERDATA* readerdata /**< the reader data */
1683  )
1684 {
1685  STOSCENARIO*** blocks;
1686  int numblocks;
1687  int* numblocksperblock;
1688  int blockssize;
1689  int* blocksperblocksize;
1690  int blocknum;
1691  int blockindex;
1692  int i;
1693  int j;
1694  char stagenames[SCIP_MAXSTRLEN];
1695  int numstages;
1696  SCIP_Bool foundblock;
1697 
1698  SCIP_Real probability;
1699  char currstagename[SCIP_MAXSTRLEN];
1700 
1701  SCIPdebugMsg(scip, "read Indep\n");
1702 
1703  /* This has to be the Line with the name. */
1704  if( stoinputField1(stoi) == NULL )
1705  {
1706  stoinputSyntaxerror(stoi);
1707  return SCIP_OKAY;
1708  }
1709 
1710  stoinputSetStochtype(stoi, stoinputField1(stoi));
1711 
1712  /* initializing the block data */
1713  numblocks = 0;
1714  blockssize = STO_DEFAULT_ARRAYSIZE;
1716  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &numblocksperblock, STO_DEFAULT_ARRAYSIZE) );
1717  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &blocksperblocksize, STO_DEFAULT_ARRAYSIZE) );
1718 
1719  /* initializing the stage names record */
1720  numstages = 0;
1721  (void) SCIPsnprintf(stagenames, SCIP_MAXSTRLEN, "");
1722 
1723  while( stoinputReadLine(stoi) )
1724  {
1725  if( stoinputField0(stoi) != NULL )
1726  {
1727  if( !strcmp(stoinputField0(stoi), "INDEP") )
1728  {
1730  }
1731  else if( !strcmp(stoinputField0(stoi), "ENDATA") )
1732  {
1733  SCIP_CALL( createScenariosFromBlocks(scip, readerdata, blocks, numblocks, numblocksperblock, numstages) );
1735  }
1736  else
1737  stoinputSyntaxerror(stoi);
1738 
1739  goto TERMINATE;
1740  }
1741 
1742  /* if the 5th input is NULL, then the 4th input is the probability. Otherwise, the 4th input is the stage name and
1743  * the 5th input is the probability. The stage name is redundant information, but sometimes included for more
1744  * information.
1745  */
1746  if( stoinputField5(stoi) == NULL )
1747  {
1748  probability = atof(stoinputField4(stoi));
1749  (void) SCIPsnprintf(currstagename, SCIP_MAXSTRLEN, "%s", SCIPtimConsGetStageName(scip, stoinputField2(stoi)));
1750  }
1751  else
1752  {
1753  probability = atof(stoinputField5(stoi));
1754  (void) SCIPsnprintf(currstagename, SCIP_MAXSTRLEN, "%s", stoinputField4(stoi));
1755  }
1756 
1757  /* checking whether the stage has been added previously */
1758  if( strstr(stagenames, currstagename) == NULL )
1759  {
1760  /* recording the stage name as processed */
1761  (void) SCIPsnprintf(stagenames, SCIP_MAXSTRLEN, "%s_%s", stagenames, currstagename);
1762 
1763  numstages++;
1764  }
1765 
1766  foundblock = FALSE;
1767 
1768  /* determining whether a block name has previously been added */
1769  for( i = 0; i < numblocks; i++ )
1770  {
1771  if( strcmp(getScenarioName(blocks[i][0]), stoinputField2(stoi)) == 0 )
1772  {
1773  foundblock = TRUE;
1774  break;
1775  }
1776  }
1777  blocknum = i;
1778 
1779  /* if the block is found, then the memory for the blocks array must be ensured */
1780  if( foundblock )
1781  {
1782  /* ensuring enough memory is available for the blocks */
1783  if( numblocksperblock[blocknum] + 1 > blocksperblocksize[blocknum] )
1784  {
1785  int newsize;
1786  newsize = SCIPcalcMemGrowSize(scip, numblocksperblock[blocknum] + 1);
1787  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &blocks[blocknum], blocksperblocksize[blocknum], newsize) ); /*lint !e866*/
1788  blocksperblocksize[blocknum] = newsize;
1789  }
1790  }
1791  else
1792  {
1793  /* ensuring enough memory is available for the blocks */
1794  if( numblocks + 1 > blockssize )
1795  {
1796  int newsize;
1797  newsize = SCIPcalcMemGrowSize(scip, numblocks + 1);
1798  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &blocks, blockssize, newsize) );
1799  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &numblocksperblock, blockssize, newsize) );
1800  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &blocksperblocksize, blockssize, newsize) );
1801  blockssize = newsize;
1802  }
1803 
1804  blocksperblocksize[blocknum] = STO_DEFAULT_BLOCKARRAYSIZE;
1805  numblocksperblock[blocknum] = 0;
1806  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &blocks[blocknum], blocksperblocksize[blocknum]) );
1807  }
1808 
1809  blockindex = numblocksperblock[blocknum];
1810 
1811  /* creating the scenario data structure */
1812  SCIP_CALL( createScenarioData(scip, &blocks[blocknum][blockindex]) );
1813 
1814  SCIP_CALL( setScenarioName(scip, blocks[blocknum][blockindex], stoinputField2(stoi)) );
1815  SCIP_CALL( setScenarioStageName(scip, blocks[blocknum][blockindex], currstagename) );
1816  SCIP_CALL( setScenarioProbability(scip, blocks[blocknum][blockindex], probability) );
1817  numblocksperblock[blocknum]++;
1818 
1819  if( !foundblock )
1820  numblocks++;
1821 
1822  SCIP_CALL( addScenarioEntry(scip, blocks[blocknum][blockindex], stoinputField2(stoi), stoinputField1(stoi),
1823  atof(stoinputField3(stoi))) );
1824  }
1825  stoinputSyntaxerror(stoi);
1826 
1827 TERMINATE:
1828 
1829  /* releasing the scenario data */
1830  for( i = numblocks - 1; i >= 0; i-- )
1831  {
1832  for( j = numblocksperblock[i] - 1; j >= 0; j-- )
1833  SCIP_CALL( freeScenarioTree(scip, &blocks[i][j]) );
1834  }
1835 
1836  for( i = numblocks - 1; i >= 0; i-- )
1837  SCIPfreeBlockMemoryArray(scip, &blocks[i], blocksperblocksize[i]);
1838  SCIPfreeBlockMemoryArray(scip, &blocksperblocksize, blockssize);
1839  SCIPfreeBlockMemoryArray(scip, &numblocksperblock, blockssize);
1840  SCIPfreeBlockMemoryArray(scip, &blocks, blockssize);
1841 
1842  return SCIP_OKAY;
1843 }
1844 
1845 
1846 /** computes the probability of a scenario */
1847 static
1849  SCIP* scip, /**< the SCIP data structure */
1850  STOSCENARIO* scenario /**< the current scenario */
1851  )
1852 {
1853  STOSCENARIO* checkscen;
1854  SCIP_Real probability;
1855 
1856  assert(scip != NULL);
1857  assert(scenario != NULL);
1858 
1859  /* computing the probability for the scenario */
1860  checkscen = scenario;
1861  probability = 1;
1862  while( checkscen != NULL )
1863  {
1864  probability *= getScenarioProbability(scip, checkscen);
1865  checkscen = getScenarioParent(checkscen);
1866  }
1867 
1868  return probability;
1869 }
1870 
1871 /** gets the variable name */
1872 static
1874  char* name, /**< the name to be returned */
1875  const char* varname, /**< the root of the variable name */
1876  int stagenum, /**< the stage number */
1877  int scenarionum /**< the scenario number */
1878  )
1879 {
1880  if( stagenum < 0 )
1881  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_00_%d", varname, scenarionum);
1882  else
1883  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_%d_%d", varname, stagenum, scenarionum);
1884 }
1885 
1886 
1887 /** add variables to the scenario */
1888 static
1890  SCIP* scip, /**< the SCIP data structure */
1891  STOSCENARIO* scenario, /**< the current scenario */
1892  SCIP_VAR** vars, /**< the variables of the core problem associated with this scenario */
1893  int nvars /**< the number of variables for this scenario */
1894  )
1895 {
1896  SCIP_Real probability;
1897  int i;
1898  char name[SCIP_MAXSTRLEN];
1899 
1900  assert(scip != NULL);
1901  assert(scenario != NULL);
1902  assert(vars != NULL);
1903 
1904  /* computing the probability for the scenario */
1905  probability = computeScenarioProbability(scip, scenario);
1906 
1907  for( i = 0; i < nvars; i++ )
1908  {
1909  SCIP_VAR* var;
1910  SCIP_Real obj;
1911  SCIP_VARTYPE vartype;
1912 
1913  SCIPdebugMessage("Original problem variable <%s> is being duplicated for scenario %d\n", SCIPvarGetName(vars[i]),
1914  getScenarioNum(scip, scenario));
1915 
1916  if( SCIPvarIsDeleted(vars[i]) )
1917  continue;
1918 
1919  obj = SCIPvarGetObj(vars[i])*probability;
1920 
1921  vartype = SCIPvarGetType(vars[i]);
1922 #if 0
1923  if( getScenarioStageNum(scip, scenario) == 0 )
1924  vartype = SCIPvarGetType(vars[i]);
1925  else
1926  vartype = SCIP_VARTYPE_CONTINUOUS;
1927 #endif
1928 
1929  /* creating a variable as a copy of the original variable. */
1930  getScenarioEntityName(name, SCIPvarGetName(vars[i]), getScenarioStageNum(scip, scenario), getScenarioNum(scip, scenario));
1931  SCIP_CALL( SCIPcreateVar(scip, &var, name, SCIPvarGetLbOriginal(vars[i]), SCIPvarGetUbOriginal(vars[i]),
1932  obj, vartype, SCIPvarIsInitial(vars[i]), SCIPvarIsRemovable(vars[i]), NULL, NULL, NULL,
1933  NULL, NULL) );
1934 
1935  SCIPdebugMessage("Adding variable <%s>\n", name);
1936 
1937  SCIP_CALL( SCIPaddVar(scip, var) );
1938  SCIP_CALL( SCIPreleaseVar(scip, &var) );
1939  }
1940 
1941  return SCIP_OKAY;
1942 }
1943 
1944 
1945 /** finds the scenario variable to add to a constraint */
1946 static
1948  SCIP* scip, /**< the SCIP data structure */
1949  STOSCENARIO* scenario, /**< the current scenario */
1950  SCIP_VAR* consvar, /**< the variable in the constraint that is being searched for */
1951  SCIP_VAR** scenariovar /**< pointer to return the variable to be added to the constraint */
1952  )
1953 {
1954  STOSCENARIO* checkscen;
1955  char varname[SCIP_MAXSTRLEN];
1956 
1957  assert(scip != NULL);
1958  assert(scenario != NULL);
1959  assert(consvar != NULL);
1960  assert(scenariovar != NULL);
1961 
1962  (*scenariovar) = NULL;
1963 
1964  checkscen = scenario;
1965 
1966  /* NOTE: if the variable does not exist, then we need to search the preceding scenarios. In the case of
1967  * decomposition, then we only check the preceding scenario. As such, a check count is used to limit the number
1968  * of scenario checks. */
1969  while( (*scenariovar) == NULL )
1970  {
1971  assert(checkscen != NULL);
1972  if( getScenarioStageNum(scip, checkscen) == 0 )
1973  (void) SCIPsnprintf(varname, SCIP_MAXSTRLEN, "%s", SCIPvarGetName(consvar));
1974  else
1975  getScenarioEntityName(varname, SCIPvarGetName(consvar), getScenarioStageNum(scip, checkscen),
1976  getScenarioNum(scip, checkscen));
1977 
1978  (*scenariovar) = SCIPfindVar(scip, varname);
1979 
1980  checkscen = getScenarioParent(checkscen);
1981  }
1982 
1983  if( (*scenariovar) == NULL )
1984  {
1985  SCIPerrorMessage("There is no scenario variable could be found.\n");
1986  return SCIP_READERROR;
1987  }
1988 
1989  return SCIP_OKAY;
1990 }
1991 
1992 
1993 /** create variable for the decomposed scenario */
1994 static
1996  SCIP* scip, /**< the SCIP data structure */
1997  STOSCENARIO* scenario, /**< the current scenario */
1998  SCIP_VAR* consvar, /**< the variable in the constraint that is being searched for */
1999  SCIP_VAR** scenariovar, /**< pointer to return the variable to be added to the constraint */
2000  SCIP_Bool* varadded /**< pointer to indicate whether a variable has been added */
2001  )
2002 {
2003  STOSCENARIO* checkscen;
2004  SCIP_VAR* searchvar;
2005  int checkcount;
2006  char varname[SCIP_MAXSTRLEN];
2007 
2008  assert(scip != NULL);
2009  assert(scenario != NULL);
2010  assert(consvar != NULL);
2011 
2012  (*varadded) = FALSE;
2013 
2014  /* finding the scenario that the consvar belongs to */
2015  checkscen = scenario;
2016  searchvar = NULL;
2017  checkcount = 0;
2018  while( searchvar == NULL && checkcount < 2 )
2019  {
2020  assert(checkscen != NULL);
2021  if( getScenarioStageNum(scip, checkscen) == 0 )
2022  (void) SCIPsnprintf(varname, SCIP_MAXSTRLEN, "%s", SCIPvarGetName(consvar));
2023  else
2024  getScenarioEntityName(varname, SCIPvarGetName(consvar), getScenarioStageNum(scip, checkscen),
2025  getScenarioNum(scip, checkscen));
2026 
2027  /* first checking whether the variable is included in the scenario */
2028  searchvar = SCIPfindVar(scip, varname);
2029  if( searchvar != NULL )
2030  {
2031  (*scenariovar) = searchvar;
2032  return SCIP_OKAY;
2033  }
2034 
2035  searchvar = SCIPfindVar(getScenarioScip(checkscen), varname);
2036 
2037  checkscen = getScenarioParent(checkscen);
2038  checkcount++;
2039  }
2040 
2041  if( searchvar != NULL )
2042  {
2043  SCIP_VAR* var;
2044  /* creating a variable as a copy of the original variable. */
2045  SCIP_CALL( SCIPcreateVar(scip, &var, varname, SCIPvarGetLbOriginal(searchvar), SCIPvarGetUbOriginal(searchvar),
2046  0.0, SCIPvarGetType(searchvar), SCIPvarIsInitial(searchvar), SCIPvarIsRemovable(searchvar), NULL, NULL,
2047  NULL, NULL, NULL) );
2048 
2049  SCIP_CALL( SCIPaddVar(scip, var) );
2050 
2051  (*scenariovar) = var;
2052  (*varadded) = TRUE;
2053  }
2054 
2055  return SCIP_OKAY;
2056 }
2057 
2058 
2059 /** adds the constraint to the scenario problem */
2060 static
2062  SCIP* scip, /**< the SCIP data structure */
2063  STOSCENARIO* scenario, /**< the current scenario */
2064  SCIP_CONS** conss, /**< the constraints of the core problem associated with this scenario */
2065  int nconss, /**< the number of constraints for this scenario */
2066  SCIP_Bool decomp /**< is the problem being decomposed */
2067  )
2068 {
2069  int i;
2070  int j;
2071  char name[SCIP_MAXSTRLEN];
2072  SCIP_Bool varadded;
2073 
2074  assert(scip != NULL);
2075  assert(scenario != NULL);
2076  assert(conss != NULL);
2077 
2078  /* Add constraints */
2079  /* NOTE: It is assumed that the problems only have linear constraints */
2080  for( i = 0; i < nconss; i++ )
2081  {
2082  SCIP_CONS* cons;
2083  SCIP_VAR** consvars;
2084  SCIP_Real* consvals;
2085  int nconsvars;
2086 
2087  if( SCIPconsIsDeleted(conss[i]) )
2088  continue;
2089 
2090  /* creating a linear constraint as a copy of the original constraint. */
2091  getScenarioEntityName(name, SCIPconsGetName(conss[i]), getScenarioStageNum(scip, scenario), getScenarioNum(scip, scenario));
2092  SCIP_CALL( SCIPcreateConsLinear(scip, &cons, name, 0, NULL, NULL, SCIPgetLhsLinear(scip, conss[i]),
2093  SCIPgetRhsLinear(scip, conss[i]), SCIPconsIsInitial(conss[i]), SCIPconsIsSeparated(conss[i]),
2094  SCIPconsIsEnforced(conss[i]), SCIPconsIsChecked(conss[i]), SCIPconsIsMarkedPropagate(conss[i]),
2095  SCIPconsIsLocal(conss[i]), SCIPconsIsModifiable(conss[i]), SCIPconsIsDynamic(conss[i]),
2096  SCIPconsIsRemovable(conss[i]), SCIPconsIsStickingAtNode(conss[i])) );
2097 
2098  consvars = SCIPgetVarsLinear(scip, conss[i]);
2099  consvals = SCIPgetValsLinear(scip, conss[i]);
2100  nconsvars = SCIPgetNVarsLinear(scip, conss[i]);
2101 
2102  for( j = 0; j < nconsvars; j++ )
2103  {
2104  SCIP_VAR* scenariovar;
2105 
2106  scenariovar = NULL;
2107 
2108  varadded = FALSE;
2109 
2110  if( decomp )
2111  SCIP_CALL( getScenarioDecompVar(scip, scenario, consvars[j], &scenariovar, &varadded) );
2112  else
2113  SCIP_CALL( findScenarioVar(scip, scenario, consvars[j], &scenariovar) );
2114 
2115  if( scenariovar != NULL )
2116  SCIP_CALL( SCIPaddCoefLinear(scip, cons, scenariovar, consvals[j]) );
2117 
2118  if( varadded )
2119  SCIP_CALL( SCIPreleaseVar(scip, &scenariovar) );
2120  }
2121 
2122  SCIP_CALL( SCIPaddCons(scip, cons) );
2123  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
2124  }
2125 
2126  return SCIP_OKAY;
2127 }
2128 
2129 /** add variables and constraint to problem */
2130 static
2132  SCIP* scip, /**< the SCIP data structure of master problem */
2133  STOSCENARIO* scenario, /**< the current scenario */
2134  SCIP_Bool decomp /**< is the problem being decomposed */
2135  )
2136 {
2137  SCIP* scenarioscip;
2138  SCIP_CONS** conss;
2139  SCIP_VAR** vars;
2140  SCIP_Real probability;
2141  int nconss;
2142  int nvars;
2143  int nentries;
2144  int stagenum;
2145  int i;
2146  char name[SCIP_MAXSTRLEN];
2147 
2148  assert(scip != NULL);
2149  assert(scenario != NULL);
2150 
2151  stagenum = SCIPtimFindStage(scip, getScenarioStageName(scip, scenario));
2152  if( stagenum < 0 || stagenum >= SCIPtimGetNStages(scip) )
2153  {
2154  SCIPerrorMessage("Unable to build stochastic program - stage <%s> was not found\n",
2155  getScenarioStageName(scip, scenario));
2156  return SCIP_READERROR;
2157  }
2158 
2159  SCIPdebugMessage("Creating scenario at stage <%d>. Scenario: %d Stage: %d\n", stagenum, getScenarioNum(scip, scenario),
2160  getScenarioStageNum(scip, scenario));
2161 
2162  conss = SCIPtimGetStageConss(scip, stagenum);
2163  nconss = SCIPtimGetStageNConss(scip, stagenum);
2164  vars = SCIPtimGetStageVars(scip, stagenum);
2165  nvars = SCIPtimGetStageNVars(scip, stagenum);
2166 
2167  /* this if 0 will be removed when the stochastic reader is merged with the Benders' branch */
2168  if( decomp )
2169  {
2170  SCIP_CALL( SCIPcreate(&scenarioscip) );
2171 
2172  getScenarioEntityName(name, SCIPgetProbName(scip), getScenarioStageNum(scip, scenario), getScenarioNum(scip, scenario));
2173 
2174  /* creating the problem */
2175  SCIP_CALL( SCIPcreateProbBasic(scenarioscip, name) );
2176 
2177  /* we explicitly enable the use of a debug solution for this main SCIP instance */
2178  SCIPenableDebugSol(scenarioscip);
2179 
2180  /* include default SCIP plugins */
2181  SCIP_CALL( SCIPincludeDefaultPlugins(scenarioscip) );
2182 
2183  /* activating the Benders' constraint handler for the scenario stages.
2184  * TODO: consider whether the two-phase method should be activated by default in the scenario stages.
2185  */
2186  SCIP_CALL( SCIPsetBoolParam(scenarioscip, "constraints/benders/active", TRUE) );
2187 
2188  /* allocating memory for the subproblems */
2189  if( getScenarioNChildren(scenario) > 0 )
2190  SCIP_CALL( createScenarioSubproblemArray(scenarioscip, scenario) );
2191  }
2192  else
2193  scenarioscip = scip;
2194 
2195  /* adding the scenarioscip to the scenario */
2196  setScenarioScip(scenario, scenarioscip);
2197 
2198  /* adding the variables to the scenario */
2199  SCIP_CALL( addScenarioVarsToProb(scenarioscip, scenario, vars, nvars) );
2200 
2201  /* adding the constraints to the scenario */
2202  SCIP_CALL( addScenarioConsToProb(scenarioscip, scenario, conss, nconss, decomp) );
2203 
2204  /* add the variables and constraints of the child scenarios */
2205  for( i = 0; i < getScenarioNChildren(scenario); i++ )
2206  {
2207  /* the master SCIP is always passed to the recursive function. The scenario SCIP instances are generated in the
2208  * function call. */
2209  SCIP_CALL( addScenarioVarsAndConsToProb(scip, getScenarioChild(scenario, i), decomp) );
2210  if( decomp )
2211  addScenarioSubproblem(scenario, getScenarioScip(getScenarioChild(scenario, i)));
2212  }
2213 
2214  /* adding the Benders' decomposition */
2215  if( decomp && getScenarioNChildren(scenario) > 0 )
2217 
2218  /* computing the probability for the scenario */
2219  probability = computeScenarioProbability(scenarioscip, scenario);
2220 
2221  /* change the constraints for the given scenario */
2222  nentries = getScenarioNEntries(scenario);
2223  for( i = 0; i < nentries; i++ )
2224  {
2225  SCIP_CONS* cons;
2226  SCIP_VAR* var;
2227  char RHS[] = "RHS";
2228  char rhs[] = "rhs";
2229  char RIGHT[] = "RIGHT";
2230  char MINI[] = "MINI";
2231  char obj[] = "obj";
2232  char OBJ[] = "OBJ";
2233 
2234  /* finding the constraint associated with the row */
2235  getScenarioEntityName(name, getScenarioEntryRow(scenario, i), getScenarioStageNum(scenarioscip, scenario),
2236  getScenarioNum(scenarioscip, scenario));
2237  cons = SCIPfindCons(scenarioscip, name);
2238 
2239  if( strncmp(getScenarioEntryCol(scenario, i), RHS, 3) == 0 ||
2240  strncmp(getScenarioEntryCol(scenario, i), rhs, 3) == 0 ||
2241  strcmp(getScenarioEntryCol(scenario, i), RIGHT) == 0 )
2242  {
2243  /* if the constraint is NULL, then it is not possible to make any changes to the scenario */
2244  if( cons == NULL )
2245  {
2246  SCIPerrorMessage("There is no constraint <%s> in the current scenario.\n", name);
2247  return SCIP_READERROR;
2248  }
2249 
2250  /* if the constraint is an equality constraint, then the LHS must also be changed */
2251  if( SCIPgetLhsLinear(scenarioscip, cons) >= SCIPgetRhsLinear(scenarioscip, cons) )
2252  {
2253  SCIP_CALL( SCIPchgLhsLinear(scenarioscip, cons, getScenarioEntryValue(scenario, i)) );
2254  SCIP_CALL( SCIPchgRhsLinear(scenarioscip, cons, getScenarioEntryValue(scenario, i)) );
2255  }
2256  else if( SCIPisLT(scenarioscip, SCIPgetRhsLinear(scenarioscip, cons), SCIPinfinity(scenarioscip)) )
2257  SCIP_CALL( SCIPchgRhsLinear(scenarioscip, cons, getScenarioEntryValue(scenario, i)) );
2258  else if( SCIPisLT(scenarioscip, SCIPgetLhsLinear(scenarioscip, cons), SCIPinfinity(scenarioscip)) )
2259  SCIP_CALL( SCIPchgLhsLinear(scenarioscip, cons, getScenarioEntryValue(scenario, i)) );
2260  }
2261  else if( strstr(getScenarioEntryRow(scenario, i), MINI) != NULL ||
2262  strstr(getScenarioEntryRow(scenario, i), obj) != NULL ||
2263  strstr(getScenarioEntryRow(scenario, i), OBJ) != NULL )
2264  {
2265  /* finding the variable associated with the column */
2266  getScenarioEntityName(name, getScenarioEntryCol(scenario, i), getScenarioStageNum(scenarioscip, scenario),
2267  getScenarioNum(scenarioscip, scenario));
2268  var = SCIPfindVar(scenarioscip, name);
2269 
2270  /* changing the coefficient for the variable */
2271  if( var == NULL )
2272  {
2273  SCIPerrorMessage("There is no variable <%s> in the current scenario.\n", name);
2274  return SCIP_READERROR;
2275  }
2276  else
2277  {
2278  SCIP_CALL( SCIPchgVarObj(scenarioscip, var, getScenarioEntryValue(scenario, i)*probability) );
2279  }
2280  }
2281  else
2282  {
2283  /* if the constraint is NULL, then it is not possible to make any changes to the scenario */
2284  if( cons == NULL )
2285  {
2286  SCIPerrorMessage("There is no constraint <%s> in the current scenario.\n", name);
2287  return SCIP_READERROR;
2288  }
2289 
2290  /* finding the variable associated with the column */
2291  getScenarioEntityName(name, getScenarioEntryCol(scenario, i), getScenarioStageNum(scenarioscip, scenario),
2292  getScenarioNum(scenarioscip, scenario));
2293  var = SCIPfindVar(scenarioscip, name);
2294 
2295  if( var == NULL )
2296  {
2297  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s", getScenarioEntryCol(scenario, i));
2298  var = SCIPfindVar(scenarioscip, name);
2299  }
2300 
2301  /* changing the coefficient for the variable */
2302  if( var == NULL )
2303  {
2304  SCIPerrorMessage("There is no variable <%s> in the current scenario.\n", name);
2305  return SCIP_READERROR;
2306  }
2307  else
2308  {
2309  SCIP_CALL( SCIPchgCoefLinear(scenarioscip, cons, var, getScenarioEntryValue(scenario, i)) );
2310  }
2311  }
2312  }
2313 
2314  return SCIP_OKAY;
2315 }
2316 
2317 /** removes the core variables and constriants for stage 2 and lower */
2318 static
2320  SCIP* scip /**< the SCIP data structure */
2321  )
2322 {
2323  SCIP_CONS** conss;
2324  SCIP_VAR** vars;
2325  int nconss;
2326  int nvars;
2327  int numstages;
2328  int i;
2329  int j;
2330  SCIP_Bool deleted;
2331 
2332  assert(scip != NULL);
2333 
2334  numstages = SCIPtimGetNStages(scip);
2335 
2336  /* looping through all stages to remove the variables and constraints. The first stage is not removed as these are
2337  * part of the complete problem */
2338  for( i = 1; i < numstages; i++ )
2339  {
2340  conss = SCIPtimGetStageConss(scip, i);
2341  vars = SCIPtimGetStageVars(scip, i);
2342  nconss = SCIPtimGetStageNConss(scip, i);
2343  nvars = SCIPtimGetStageNVars(scip, i);
2344 
2345  /* removing constriants */
2346  for( j = 0; j < nconss; j++ )
2347  {
2348  if( !SCIPconsIsDeleted(conss[j]) )
2349  SCIP_CALL( SCIPdelCons(scip, conss[j]) );
2350  }
2351 
2352  /* removing variables */
2353  for( j = 0; j < nvars; j++ )
2354  {
2355  if( !SCIPvarIsDeleted(vars[j]) )
2356  {
2357  SCIP_CALL( SCIPdelVar(scip, vars[j], &deleted) );
2358  assert(deleted);
2359  }
2360  }
2361  }
2362 
2363  return SCIP_OKAY;
2364 }
2365 
2366 
2367 /* build the stochastic program completely as a MIP, i.e. no decomposition */
2368 static
2370  SCIP* scip, /**< the SCIP data structure */
2371  SCIP_READERDATA* readerdata /**< the reader data */
2372  )
2373 {
2374  int i;
2375 
2376  assert(scip != NULL);
2377  assert(readerdata != NULL);
2378 
2379  /* adding all variables and constraints for stages below the first stage.
2380  * The first stage is covered by the original problem. */
2381  for( i = 0; i < getScenarioNChildren(readerdata->scenariotree); i++ )
2382  SCIP_CALL( addScenarioVarsAndConsToProb(scip, getScenarioChild(readerdata->scenariotree, i), FALSE) );
2383 
2384  /* removing the variable and constraints that were included as part of the core file */
2386 
2387  return SCIP_OKAY;
2388 }
2389 
2390 
2391 /** builds the stochastic program using Benders' decomposition */
2392 static
2394  SCIP* scip, /**< the SCIP data structure */
2395  SCIP_READERDATA* readerdata /**< the reader data */
2396  )
2397 {
2398  int i;
2399 
2400  assert(scip != NULL);
2401  assert(readerdata != NULL);
2402 
2403  SCIP_CALL( createScenarioSubproblemArray(scip, readerdata->scenariotree) );
2404 
2405  /* activating the Benders' constraint handler. The two-phase method is activated by default. If the user desires not
2406  * to use the two-phase method, then the setting in cons_benderslp must be explicitly changed.
2407  */
2408  SCIP_CALL( SCIPsetBoolParam(scip, "constraints/benders/active", TRUE) );
2409  SCIP_CALL( SCIPsetBoolParam(scip, "constraints/benderslp/active", TRUE) );
2410 
2411  setScenarioScip(readerdata->scenariotree, scip);
2412 
2413  /* adding all variables and constraints for stages below the first stage.
2414  * The first stage is covered by the original problem. */
2415  for( i = 0; i < getScenarioNChildren(readerdata->scenariotree); i++ )
2416  {
2417  SCIP_CALL( addScenarioVarsAndConsToProb(scip, getScenarioChild(readerdata->scenariotree, i), TRUE) );
2418  addScenarioSubproblem(readerdata->scenariotree, getScenarioScip(getScenarioChild(readerdata->scenariotree, i)));
2419  }
2420 
2421  /* creating the Benders' decomposition */
2422  SCIP_CALL( SCIPcreateBendersDefault(scip, getScenarioSubproblemArray(readerdata->scenariotree),
2423  getScenarioNChildren(readerdata->scenariotree)) );
2424 
2425  /* removing the variable and constraints that were included as part of the core file */
2427 
2428  /* changing settings that are required for Benders' decomposition */
2430  SCIP_CALL( SCIPsetIntParam(scip, "constraints/benders/maxprerounds", 1) );
2431  SCIP_CALL( SCIPsetIntParam(scip, "presolving/maxrounds", 1) );
2432  SCIP_CALL( SCIPsetIntParam(scip, "propagating/maxrounds", 0) );
2433  SCIP_CALL( SCIPsetIntParam(scip, "propagating/maxroundsroot", 0) );
2434  SCIP_CALL( SCIPsetIntParam(scip, "heuristics/trysol/freq", 1) );
2435 
2436  SCIP_CALL( SCIPsetIntParam(scip, "benders/default/lnsmaxdepth", 10) );
2437 
2438  return SCIP_OKAY;
2439 }
2440 
2441 /** Read the stochastic information of an SMPS file instance in "STO File Format". */
2442 static
2444  SCIP* scip, /**< SCIP data structure */
2445  const char* filename, /**< name of the input file */
2446  SCIP_READERDATA* readerdata /**< the reader data */
2447  )
2448 {
2449  SCIP_FILE* fp;
2450  STOINPUT* stoi;
2451  SCIP_RETCODE retcode;
2452  SCIP_Bool error = TRUE;
2453  SCIP_Bool unsupported = FALSE;
2454 
2455  assert(scip != NULL);
2456  assert(filename != NULL);
2457 
2458  fp = SCIPfopen(filename, "r");
2459  if( fp == NULL )
2460  {
2461  SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
2462  SCIPprintSysError(filename);
2463  return SCIP_NOFILE;
2464  }
2465 
2466  SCIP_CALL_FINALLY( stoinputCreate(scip, &stoi, fp), SCIPfclose(fp) );
2467  SCIP_CALL_TERMINATE( retcode, createReaderdata(scip, readerdata), TERMINATE );
2468 
2469  SCIP_CALL_TERMINATE( retcode, readStoch(scip, stoi), TERMINATE );
2470 
2471  /* checking for supported stochastic information types */
2473  {
2474  SCIPinfoMessage(scip, NULL, "\nSorry, currently only STO files with the stochastic information as DISCRETE are supported.\n\n");
2475  SCIPinfoMessage(scip, NULL, "NOTE: The problem provided by the COR file is loaded without stochastic information.\n\n");
2476  unsupported = TRUE;
2477  }
2478  else
2479  {
2480  if( stoinputSection(stoi) == STO_BLOCKS )
2481  {
2482  SCIP_CALL_TERMINATE( retcode, readBlocks(stoi, scip, readerdata), TERMINATE );
2483  }
2484 
2485  if( stoinputSection(stoi) == STO_SCENARIOS )
2486  {
2487  /* if there are more than two stages, then the sto file is not read. */
2488  if( SCIPtimGetNStages(scip) > 2 )
2489  {
2490  SCIPinfoMessage(scip, NULL, "\nThe scenarios for the stochastic programs are defined in <%s> as SCENARIOS\n", filename);
2491  SCIPinfoMessage(scip, NULL, "Sorry, currently only two-stage stochastic programs are supported when scenarios are defined as SCENARIOS.\n\n");
2492  SCIPinfoMessage(scip, NULL, "NOTE: The problem provided by the COR file is loaded without stochastic information.\n\n");
2493  unsupported = TRUE;
2494  }
2495  else
2496  {
2497  SCIP_CALL_TERMINATE( retcode, readScenarios(stoi, scip, readerdata), TERMINATE );
2498  }
2499  }
2500 
2501  if( stoinputSection(stoi) == STO_INDEP )
2502  {
2503  SCIP_CALL_TERMINATE( retcode, readIndep(stoi, scip, readerdata), TERMINATE );
2504  }
2505  }
2506 
2507  if( !unsupported && stoinputSection(stoi) != STO_ENDATA )
2508  stoinputSyntaxerror(stoi);
2509 
2510  error = stoinputHasError(stoi);
2511 
2512  if( !error && !unsupported )
2513  {
2514  if( readerdata->usebenders )
2515  {
2516  SCIP_CALL_TERMINATE( retcode, buildDecompProblem(scip, readerdata), TERMINATE );
2517  }
2518  else
2519  {
2520  SCIP_CALL_TERMINATE( retcode, buildFullProblem(scip, readerdata), TERMINATE );
2521  }
2522  }
2523 
2524 /* cppcheck-suppress unusedLabel */
2525 TERMINATE:
2526  stoinputFree(scip, &stoi);
2527  SCIPfclose(fp);
2528 
2529  if( error || retcode != SCIP_OKAY )
2530  return SCIP_READERROR;
2531  else
2532  return SCIP_OKAY;
2533 }
2534 
2535 
2536 /*
2537  * Callback methods of reader
2538  */
2539 
2540 /** copy method for reader plugins (called when SCIP copies plugins) */
2541 static
2542 SCIP_DECL_READERCOPY(readerCopySto)
2543 { /*lint --e{715}*/
2544  assert(scip != NULL);
2545  assert(reader != NULL);
2546  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
2547 
2548  /* call inclusion method of reader */
2550 
2551  return SCIP_OKAY;
2552 }
2553 
2554 /** destructor of reader to free user data (called when SCIP is exiting) */
2555 static
2556 SCIP_DECL_READERFREE(readerFreeSto)
2557 {
2558  SCIP_READERDATA* readerdata;
2559 
2560  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
2561  readerdata = SCIPreaderGetData(reader);
2562  assert(readerdata != NULL);
2563 
2564  SCIP_CALL( freeReaderdata(scip, readerdata) );
2565 
2566  return SCIP_OKAY;
2567 }
2568 
2569 /** problem reading method of reader */
2570 static
2571 SCIP_DECL_READERREAD(readerReadSto)
2572 { /*lint --e{715}*/
2573  SCIP_READER* correader;
2574  SCIP_READER* timreader;
2575 
2576  assert(reader != NULL);
2577  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
2578 
2579  correader = SCIPfindReader(scip, "correader");
2580  timreader = SCIPfindReader(scip, "timreader");
2581 
2582  if( correader == NULL )
2583  {
2584  SCIPwarningMessage(scip, "It is necessary to include the \"cor\" reader\n");
2585  (*result) = SCIP_DIDNOTRUN;
2586  return SCIP_OKAY;
2587  }
2588 
2589  if( timreader == NULL )
2590  {
2591  SCIPwarningMessage(scip, "It is necessary to include the \"tim\" reader\n");
2592  (*result) = SCIP_DIDNOTRUN;
2593  return SCIP_OKAY;
2594  }
2595 
2596  /* checking whether the cor file has been read */
2597  if( !SCIPcorHasRead(correader) )
2598  {
2599  SCIPwarningMessage(scip, "The core file must be read before the time and stochastic files.\n");
2600  (*result) = SCIP_DIDNOTRUN;
2601  return SCIP_OKAY;
2602  }
2603 
2604  /* checking whether the tim file has been read */
2605  if( !SCIPtimHasRead(timreader) )
2606  {
2607  SCIPwarningMessage(scip, "The time file must be read before the stochastic files.\n");
2608  (*result) = SCIP_DIDNOTRUN;
2609  return SCIP_OKAY;
2610  }
2611 
2612  SCIP_CALL( SCIPreadSto(scip, filename, result) );
2613 
2614  return SCIP_OKAY;
2615 }
2616 
2617 /*
2618  * sto file reader specific interface methods
2619  */
2620 
2621 /** includes the sto file reader in SCIP */
2623  SCIP* scip /**< SCIP data structure */
2624  )
2625 {
2626  SCIP_READERDATA* readerdata;
2627  SCIP_READER* reader;
2628 
2629  /* create reader data */
2630  SCIP_CALL( SCIPallocBlockMemory(scip, &readerdata) );
2631  readerdata->scenariotree = NULL;
2632  readerdata->numscenarios = 0;
2633 
2634  /* include reader */
2635  SCIP_CALL( SCIPincludeReaderBasic(scip, &reader, READER_NAME, READER_DESC, READER_EXTENSION, readerdata) );
2636 
2637  /* set non fundamental callbacks via setter functions */
2638  SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopySto) );
2639  SCIP_CALL( SCIPsetReaderFree(scip, reader, readerFreeSto) );
2640  SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadSto) );
2641 
2642  /* add decomposition parameters */
2644  "reading/" READER_NAME "/usebenders",
2645  "should Benders' decomposition be used?",
2646  &readerdata->usebenders, FALSE, DEFAULT_USEBENDERS, NULL, NULL) );
2647 
2648  return SCIP_OKAY;
2649 }
2650 
2651 
2652 /** reads the stochastic information for a stochastic program that is in SMPS format */
2654  SCIP* scip, /**< SCIP data structure */
2655  const char* filename, /**< full path and name of file to read, or NULL if stdin should be used */
2656  SCIP_RESULT* result /**< pointer to store the result of the file reading call */
2657  )
2658 {
2659  SCIP_READER* reader;
2660  SCIP_READERDATA* readerdata;
2661  SCIP_RETCODE retcode;
2662 
2663  assert(scip != NULL);
2664  assert(result != NULL);
2665 
2666  reader = SCIPfindReader(scip, READER_NAME);
2667  assert(reader != NULL);
2668  readerdata = SCIPreaderGetData(reader);
2669 
2670  retcode = readSto(scip, filename, readerdata);
2671 
2672  if( retcode == SCIP_PLUGINNOTFOUND )
2673  retcode = SCIP_READERROR;
2674 
2675  if( retcode == SCIP_NOFILE || retcode == SCIP_READERROR )
2676  return retcode;
2677 
2678  SCIP_CALL( retcode );
2679 
2680  *result = SCIP_SUCCESS;
2681 
2682  return SCIP_OKAY;
2683 }
2684 
2685 /** returns the total number of scenarios added to the problem */
2687  SCIP* scip /**< SCIP data structure */
2688  )
2689 {
2690  SCIP_READER* reader;
2691  SCIP_READERDATA* readerdata;
2692 
2693  reader = SCIPfindReader(scip, READER_NAME);
2694 
2695  assert(reader != NULL);
2696  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
2697 
2698  readerdata = SCIPreaderGetData(reader);
2699  assert(readerdata != NULL);
2700 
2701  return readerdata->numscenarios;
2702 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
#define BLANK
Definition: reader_sto.c:68
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:116
static const char * stoinputField5(const STOINPUT *stoi)
Definition: reader_sto.c:1113
SCIP_Real * values
Definition: reader_sto.c:98
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip_mem.h:105
enum StoStochInfo STOSTOCHINFO
Definition: reader_sto.c:126
#define NULL
Definition: def.h:246
int SCIPmemccpy(char *dest, const char *src, char stop, unsigned int cnt)
Definition: misc.c:10137
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:99
TIM file reader - the stage information for a stochastic programming instance in SMPS format...
static SCIP_RETCODE findScenarioVar(SCIP *scip, STOSCENARIO *scenario, SCIP_VAR *consvar, SCIP_VAR **scenariovar)
Definition: reader_sto.c:1947
public methods for SCIP parameter handling
static SCIP_Real computeScenarioProbability(SCIP *scip, STOSCENARIO *scenario)
Definition: reader_sto.c:1848
SCIP_Bool SCIPconsIsDynamic(SCIP_CONS *cons)
Definition: cons.c:8335
static SCIP_RETCODE addScenariosToReaderdata(SCIP *scip, SCIP_READERDATA *readerdata, STOSCENARIO ***scenarios, int *numscenarios, int numscenariostages)
Definition: reader_sto.c:698
const char * name
Definition: reader_sto.c:93
public methods for memory management
static const char * getScenarioEntryRow(STOSCENARIO *scenario, int entry)
Definition: reader_sto.c:517
static STOSTOCHINFO stoinputStochInfoType(const STOINPUT *stoi)
Definition: reader_sto.c:1047
#define SCIP_MAXSTRLEN
Definition: def.h:267
SCIP_Bool SCIPvarIsInitial(SCIP_VAR *var)
Definition: var.c:16931
int childrensize
Definition: reader_sto.c:88
SCIP_RETCODE SCIPdelCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2895
int stagenum
Definition: reader_sto.c:90
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip_mem.c:210
int entriessize
Definition: reader_sto.c:100
COR file reader (MPS format of the core problem for stochastic programs)
#define SCIP_CALL_FINALLY(x, y)
Definition: def.h:400
enum StoSection STOSECTION
Definition: reader_sto.c:114
const char * SCIPreaderGetName(SCIP_READER *reader)
Definition: reader.c:547
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
Definition: scip_var.c:1251
static void stoinputSetStochtype(STOINPUT *stoi, const char *stochtype)
Definition: reader_sto.c:1173
SCIP_RETCODE SCIPincludeReaderSto(SCIP *scip)
Definition: reader_sto.c:2622
#define FALSE
Definition: def.h:72
static SCIP_RETCODE addScenarioVarsAndConsToProb(SCIP *scip, STOSCENARIO *scenario, SCIP_Bool decomp)
Definition: reader_sto.c:2131
#define DEFAULT_USEBENDERS
Definition: reader_sto.c:54
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_RETCODE SCIPcreateBendersDefault(SCIP *scip, SCIP **subproblems, int nsubproblems)
static SCIP_RETCODE addScenarioEntry(SCIP *scip, STOSCENARIO *scenario, const char *rowname, const char *colname, SCIP_Real value)
Definition: reader_sto.c:474
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10253
#define TRUE
Definition: def.h:71
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
static SCIP_RETCODE setScenarioProbability(SCIP *scip, STOSCENARIO *scenario, SCIP_Real probability)
Definition: reader_sto.c:445
SCIP_Bool SCIPconsIsStickingAtNode(SCIP_CONS *cons)
Definition: cons.c:8355
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:1022
#define STO_DEFAULT_ARRAYSIZE
Definition: reader_sto.c:63
const char * f5
Definition: reader_sto.c:142
static SCIP_RETCODE setScenarioNum(SCIP *scip, STOSCENARIO *scenario, int scenarionum)
Definition: reader_sto.c:416
STO file reader - the stochastic information of an instance in SMPS format.
public methods for problem variables
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:114
static SCIP_DECL_READERCOPY(readerCopySto)
Definition: reader_sto.c:2542
SCIP_READER * SCIPfindReader(SCIP *scip, const char *name)
Definition: scip_reader.c:306
static const char * stoinputField1(const STOINPUT *stoi)
Definition: reader_sto.c:1069
#define SCIPdebugMessage
Definition: pub_message.h:77
StoStochInfo
Definition: reader_sto.c:117
STOSCENARIO * parent
Definition: reader_sto.c:85
static SCIP ** getScenarioSubproblemArray(STOSCENARIO *scenario)
Definition: reader_sto.c:285
const char * SCIPtimConsGetStageName(SCIP *scip, const char *consname)
Definition: reader_tim.c:964
static void stoinputSetProbname(STOINPUT *stoi, const char *probname)
Definition: reader_sto.c:1159
static const char * getScenarioName(STOSCENARIO *scenario)
Definition: reader_sto.c:405
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:142
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip_general.c:338
SCIP_Bool SCIPvarIsRemovable(SCIP_VAR *var)
Definition: var.c:16941
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:97
static SCIP_RETCODE readStoch(SCIP *scip, STOINPUT *stoi)
Definition: reader_sto.c:1316
public methods for SCIP variables
static SCIP_RETCODE getScenarioDecompVar(SCIP *scip, STOSCENARIO *scenario, SCIP_VAR *consvar, SCIP_VAR **scenariovar, SCIP_Bool *varadded)
Definition: reader_sto.c:1995
static SCIP_Bool stoinputReadLine(STOINPUT *stoi)
Definition: reader_sto.c:1213
SCIP_Bool SCIPconsIsRemovable(SCIP_CONS *cons)
Definition: cons.c:8345
static void getScenarioEntityName(char *name, const char *varname, int stagenum, int scenarionum)
Definition: reader_sto.c:1873
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:203
static int getScenarioNEntries(STOSCENARIO *scenario)
Definition: reader_sto.c:506
#define SCIPdebugMsg
Definition: scip_message.h:88
static STOSCENARIO * getScenarioParent(STOSCENARIO *scenario)
Definition: reader_sto.c:320
SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
const char ** colnames
Definition: reader_sto.c:97
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:279
SCIP_RETCODE SCIPcreateProbBasic(SCIP *scip, const char *name)
Definition: scip_prob.c:223
char stochtype[STO_MAX_NAMELEN]
Definition: reader_sto.c:144
static SCIP_RETCODE copyScenario(SCIP *scip, STOSCENARIO *sourcescenario, STOSCENARIO **targetscenario, SCIP_Bool copyname)
Definition: reader_sto.c:558
public methods for numerical tolerances
const char * SCIPgetProbName(SCIP *scip)
Definition: scip_prob.c:1123
#define READER_DESC
Definition: reader_sto.c:51
SCIP_VAR * SCIPfindVar(SCIP *scip, const char *name)
Definition: scip_prob.c:2737
static void addScenarioSubproblem(STOSCENARIO *scenario, SCIP *subproblem)
Definition: reader_sto.c:269
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
Definition: fileio.c:140
SCIP_READERDATA * SCIPreaderGetData(SCIP_READER *reader)
Definition: reader.c:482
STOSECTION section
Definition: reader_sto.c:131
#define SCIPduplicateBlockMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:111
SCIP_Bool SCIPtimHasRead(SCIP_READER *reader)
Definition: reader_tim.c:907
SCIP_RETCODE SCIPdelVar(SCIP *scip, SCIP_VAR *var, SCIP_Bool *deleted)
Definition: scip_prob.c:1842
public methods for managing constraints
const char * f1
Definition: reader_sto.c:138
static int getScenarioStageNum(SCIP *scip, STOSCENARIO *scenario)
Definition: reader_sto.c:376
static STOSCENARIO * findScenarioInTree(STOSCENARIO *scenariotree, const char *scenname)
Definition: reader_sto.c:729
static SCIP_RETCODE removeCoreVariablesAndConstraints(SCIP *scip)
Definition: reader_sto.c:2319
SCIP * scip
Definition: reader_sto.c:83
static SCIP_RETCODE createReaderdata(SCIP *scip, SCIP_READERDATA *readerdata)
Definition: reader_sto.c:956
static SCIP * getScenarioScip(STOSCENARIO *scenario)
Definition: reader_sto.c:243
static SCIP_RETCODE readBlocks(STOINPUT *stoi, SCIP *scip, SCIP_READERDATA *readerdata)
Definition: reader_sto.c:1377
static SCIP_Real getScenarioEntryValue(STOSCENARIO *scenario, int entry)
Definition: reader_sto.c:543
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2822
SCIP_Real SCIPvarGetLbOriginal(SCIP_VAR *var)
Definition: var.c:17290
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static const char * stoinputField0(const STOINPUT *stoi)
Definition: reader_sto.c:1058
const char * f0
Definition: reader_sto.c:137
static SCIP_RETCODE createScenarioSubproblemArray(SCIP *scip, STOSCENARIO *scenario)
Definition: reader_sto.c:254
SCIP_Real SCIPvarGetUbOriginal(SCIP_VAR *var)
Definition: var.c:17310
static const char * stoinputField3(const STOINPUT *stoi)
Definition: reader_sto.c:1091
const char ** rownames
Definition: reader_sto.c:96
static const char * stoinputField4(const STOINPUT *stoi)
Definition: reader_sto.c:1102
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip_param.c:520
struct SCIP_File SCIP_FILE
Definition: pub_fileio.h:34
char * SCIPfgets(char *s, int size, SCIP_FILE *stream)
Definition: fileio.c:187
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:8076
int nchildren
Definition: reader_sto.c:87
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16730
static SCIP_Real getScenarioProbability(SCIP *scip, STOSCENARIO *scenario)
Definition: reader_sto.c:461
static STOSECTION stoinputSection(const STOINPUT *stoi)
Definition: reader_sto.c:1036
int SCIPtimGetNStages(SCIP *scip)
Definition: reader_tim.c:924
static SCIP_RETCODE setScenarioName(SCIP *scip, STOSCENARIO *scenario, const char *name)
Definition: reader_sto.c:389
SCIP_CONS * SCIPfindCons(SCIP *scip, const char *name)
Definition: scip_prob.c:2999
SCIP_Real probability
Definition: reader_sto.c:94
static SCIP_RETCODE buildDecompProblem(SCIP *scip, SCIP_READERDATA *readerdata)
Definition: reader_sto.c:2393
static SCIP_RETCODE freeScenarioTree(SCIP *scip, STOSCENARIO **scenariotree)
Definition: reader_sto.c:185
const char * f3
Definition: reader_sto.c:140
static SCIP_RETCODE addScenarioConsToProb(SCIP *scip, STOSCENARIO *scenario, SCIP_CONS **conss, int nconss, SCIP_Bool decomp)
Definition: reader_sto.c:2061
#define SCIP_CALL(x)
Definition: def.h:358
#define SCIPensureBlockMemoryArray(scip, ptr, arraysizeptr, minsize)
Definition: scip_mem.h:113
static SCIP_Bool stoinputHasError(const STOINPUT *stoi)
Definition: reader_sto.c:1124
SCIP_Bool SCIPconsIsLocal(SCIP_CONS *cons)
Definition: cons.c:8315
#define STO_MAX_LINELEN
Definition: reader_sto.c:60
public methods for constraint handler plugins and constraints
static SCIP_RETCODE setScenarioStageNum(SCIP *scip, STOSCENARIO *scenario, int stagenum)
Definition: reader_sto.c:360
wrapper functions to map file i/o to standard or zlib file i/o
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
Definition: scip_var.c:4449
STOSCENARIO ** children
Definition: reader_sto.c:86
const char * stagename
Definition: reader_sto.c:92
static const char * stoinputField2(const STOINPUT *stoi)
Definition: reader_sto.c:1080
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:130
struct SCIP_ReaderData SCIP_READERDATA
Definition: type_reader.h:37
public data structures and miscellaneous methods
#define STO_MAX_NAMELEN
Definition: reader_sto.c:61
int SCIPtimFindStage(SCIP *scip, const char *stage)
Definition: reader_tim.c:1005
#define SCIP_Bool
Definition: def.h:69
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
SCIP_RETCODE SCIPincludeReaderBasic(SCIP *scip, SCIP_READER **readerptr, const char *name, const char *desc, const char *extension, SCIP_READERDATA *readerdata)
Definition: scip_reader.c:180
static const char * getScenarioEntryCol(STOSCENARIO *scenario, int entry)
Definition: reader_sto.c:530
static SCIP_RETCODE buildScenarioTree(SCIP *scip, STOSCENARIO **scenariotree, STOSCENARIO ***scenarios, int *numscenarios, int numstages, int stage)
Definition: reader_sto.c:652
static void stoinputSetSection(STOINPUT *stoi, STOSECTION section)
Definition: reader_sto.c:1135
void SCIPprintSysError(const char *message)
Definition: misc.c:10162
STOSTOCHINFO stochinfotype
Definition: reader_sto.c:132
SCIP_CONS ** SCIPtimGetStageConss(SCIP *scip, int stagenum)
Definition: reader_tim.c:1064
static SCIP_RETCODE mergeScenarios(SCIP *scip, STOSCENARIO *scenario1, STOSCENARIO **mergedscenario)
Definition: reader_sto.c:597
#define RIGHT
Definition: rbtree.c:33
int nentries
Definition: reader_sto.c:99
const char * f2
Definition: reader_sto.c:139
SCIP_RETCODE SCIPreadSto(SCIP *scip, const char *filename, SCIP_RESULT *result)
Definition: reader_sto.c:2653
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:578
SCIP_Bool SCIPconsIsDeleted(SCIP_CONS *cons)
Definition: cons.c:8205
static SCIP_RETCODE readScenarios(STOINPUT *stoi, SCIP *scip, SCIP_READERDATA *readerdata)
Definition: reader_sto.c:1541
#define READER_EXTENSION
Definition: reader_sto.c:52
SCIP_Bool SCIPconsIsChecked(SCIP_CONS *cons)
Definition: cons.c:8275
SCIP_Bool SCIPconsIsInitial(SCIP_CONS *cons)
Definition: cons.c:8245
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17192
SCIP_RETCODE SCIPcreateVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_DECL_VARCOPY((*varcopy)), SCIP_VARDATA *vardata)
Definition: scip_var.c:104
static const char * getScenarioStageName(SCIP *scip, STOSCENARIO *scenario)
Definition: reader_sto.c:347
SCIP_Bool haserror
Definition: reader_sto.c:135
Constraint handler for linear constraints in their most general form, .
static SCIP_RETCODE createScenariosFromBlocks(SCIP *scip, SCIP_READERDATA *readerdata, STOSCENARIO ***blocks, int numblocks, int *numblocksperblock, int numstages)
Definition: reader_sto.c:880
SCIP_RETCODE SCIPchgRhsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real rhs)
int scenarionum
Definition: reader_sto.c:91
static SCIP_RETCODE setScenarioStageName(SCIP *scip, STOSCENARIO *scenario, const char *stagename)
Definition: reader_sto.c:331
char probname[STO_MAX_NAMELEN]
Definition: reader_sto.c:143
#define STO_DEFAULT_ENTRIESSIZE
Definition: reader_sto.c:64
int SCIPtimGetStageNVars(SCIP *scip, int stagenum)
Definition: reader_tim.c:1085
SCIP_RETCODE SCIPsetReaderCopy(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERCOPY((*readercopy)))
Definition: scip_reader.c:218
static SCIP_RETCODE readIndep(STOINPUT *stoi, SCIP *scip, SCIP_READERDATA *readerdata)
Definition: reader_sto.c:1679
int nsubproblems
Definition: reader_sto.c:89
static void clearFrom(char *buf, unsigned int pos)
Definition: reader_sto.c:1199
StoSection
Definition: reader_sto.c:106
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
static int getScenarioNChildren(STOSCENARIO *scenario)
Definition: reader_sto.c:296
static SCIP_RETCODE freeReaderdata(SCIP *scip, SCIP_READERDATA *readerdata)
Definition: reader_sto.c:976
general public methods
#define READER_NAME
Definition: reader_sto.c:50
public methods for debugging
static SCIP_RETCODE scenarioAddChild(SCIP *scip, STOSCENARIO **parent, STOSCENARIO *child)
Definition: reader_sto.c:624
SCIP_Bool SCIPcorHasRead(SCIP_READER *reader)
Definition: reader_cor.c:207
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
Definition: scip_prob.c:1724
SCIP_VAR ** SCIPgetVarsLinear(SCIP *scip, SCIP_CONS *cons)
int SCIPstoGetNScenarios(SCIP *scip)
Definition: reader_sto.c:2686
static SCIP_DECL_READERFREE(readerFreeSto)
Definition: reader_sto.c:2556
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1187
#define STO_DEFAULT_BLOCKARRAYSIZE
Definition: reader_sto.c:65
public methods for message output
static SCIP_RETCODE buildScenariosFromBlocks(SCIP *scip, STOSCENARIO ***blocks, STOSCENARIO ***scenarios, STOSCENARIO ***blocksforscen, int *numblocksforscen, int numblocks, int *numblocksperblock, int *numscenarios, int *scenariossize, const char *stage, int stagenum, int blocknum)
Definition: reader_sto.c:783
static SCIP_RETCODE addScenarioVarsToProb(SCIP *scip, STOSCENARIO *scenario, SCIP_VAR **vars, int nvars)
Definition: reader_sto.c:1889
#define SCIP_Real
Definition: def.h:157
SCIP_Bool SCIPconsIsModifiable(SCIP_CONS *cons)
Definition: cons.c:8325
int lineno
Definition: reader_sto.c:134
static SCIP_RETCODE readSto(SCIP *scip, const char *filename, SCIP_READERDATA *readerdata)
Definition: reader_sto.c:2443
public methods for input file readers
#define SCIP_CALL_TERMINATE(retcode, x, TERM)
Definition: def.h:379
default Benders&#39; decomposition plugin
public methods for message handling
SCIP_Bool SCIPconsIsEnforced(SCIP_CONS *cons)
Definition: cons.c:8265
static int getScenarioNum(SCIP *scip, STOSCENARIO *scenario)
Definition: reader_sto.c:432
static SCIP_RETCODE stoinputCreate(SCIP *scip, STOINPUT **stoi, SCIP_FILE *fp)
Definition: reader_sto.c:995
SCIP_Bool SCIPconsIsSeparated(SCIP_CONS *cons)
Definition: cons.c:8255
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))
Definition: scip_reader.c:266
#define STO_DEFAULT_CHILDRENSIZE
Definition: reader_sto.c:66
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16895
SCIP ** subproblems
Definition: reader_sto.c:84
SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE createScenarioData(SCIP *scip, STOSCENARIO **scenariodata)
Definition: reader_sto.c:150
enum SCIP_Vartype SCIP_VARTYPE
Definition: type_var.h:60
SCIP_RETCODE SCIPchgLhsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real lhs)
static void stoinputSetStochInfoType(STOINPUT *stoi, STOSTOCHINFO stochinfotype)
Definition: reader_sto.c:1147
SCIP_Bool SCIPconsIsMarkedPropagate(SCIP_CONS *cons)
Definition: cons.c:8285
static STOSCENARIO * getScenarioChild(STOSCENARIO *scenario, int childnum)
Definition: reader_sto.c:307
SCIP_VAR ** SCIPtimGetStageVars(SCIP *scip, int stagenum)
Definition: reader_tim.c:1043
int SCIPfclose(SCIP_FILE *fp)
Definition: fileio.c:219
const char * f4
Definition: reader_sto.c:141
char buf[STO_MAX_LINELEN]
Definition: reader_sto.c:136
static SCIP_RETCODE buildFullProblem(SCIP *scip, SCIP_READERDATA *readerdata)
Definition: reader_sto.c:2369
int SCIPtimGetStageNConss(SCIP *scip, int stagenum)
Definition: reader_tim.c:1106
public methods for reader plugins
public methods for global and local (sub)problems
char * SCIPstrtok(char *s, const char *delim, char **ptrptr)
Definition: misc.c:10211
SCIP_Bool SCIPvarIsDeleted(SCIP_VAR *var)
Definition: var.c:16951
default SCIP plugins
static void setScenarioScip(STOSCENARIO *scenario, SCIP *scip)
Definition: reader_sto.c:230
int SCIPgetNVarsLinear(SCIP *scip, SCIP_CONS *cons)
const char * SCIPtimGetStageName(SCIP *scip, int stagenum)
Definition: reader_tim.c:943
static SCIP_RETCODE insertScenarioInReaderdata(SCIP *scip, SCIP_READERDATA *readerdata, STOSCENARIO *scenario, char *parentname)
Definition: reader_sto.c:756
SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
static void stoinputFree(SCIP *scip, STOINPUT **stoi)
Definition: reader_sto.c:1026
SCIP_RETCODE SCIPsetReaderFree(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERFREE((*readerfree)))
Definition: scip_reader.c:242
SCIP_FILE * fp
Definition: reader_sto.c:133
static SCIP_DECL_READERREAD(readerReadSto)
Definition: reader_sto.c:2571
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:129
SCIP_RETCODE SCIPchgCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:370
static void stoinputSyntaxerror(STOINPUT *stoi)
Definition: reader_sto.c:1186
void SCIPenableDebugSol(SCIP *scip)
Definition: scip_debug.c:132
memory allocation routines