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-2018 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  /* if a scenario has been created that needs to be added to the scenario tree */
1612  if( addscenario )
1613  {
1614  SCIP_CALL( insertScenarioInReaderdata(scip, readerdata, scenario, parentname) );
1615 
1616  /* freeing the scenario */
1617  SCIP_CALL( freeScenarioTree(scip, &scenario) );
1618  }
1619 
1620  if( strcmp(wrongroot, stoinputField3(stoi)) == 0 )
1621  (void) SCIPsnprintf(parentname, SCIP_MAXSTRLEN, "%s", "ROOT");
1622  else
1623  (void) SCIPsnprintf(parentname, SCIP_MAXSTRLEN, "%s", stoinputField3(stoi));
1624 
1625  /* checking whether the stage has been added previously */
1626  if( strstr(scennames, stoinputField2(stoi)) == NULL )
1627  {
1628  /* recording the stage name as processed */
1629  (void) SCIPsnprintf(tmpname, SCIP_MAXSTRLEN, "%s_%s", scennames, stoinputField2(stoi));
1630  (void) SCIPsnprintf(scennames, SCIP_MAXSTRLEN, "%s", tmpname);
1631  }
1632 
1633  /* checking whether the "common" scenario has been added yet */
1634  if( strstr(scennames, parentname) == NULL )
1635  {
1636  SCIPerrorMessage("Scenario <%s> needs to be read before scenario <%s>\n", parentname, stoinputField2(stoi));
1637  stoinputSyntaxerror(stoi);
1638  goto TERMINATE;
1639  }
1640 
1641  /* the "common" scenario has been added before, so a child can be added to the scenario tree */
1642  SCIP_CALL( createScenarioData(scip, &scenario) );
1643 
1644  SCIP_CALL( setScenarioName(scip, scenario, stoinputField2(stoi)) );
1645  SCIP_CALL( setScenarioStageName(scip, scenario, stoinputField5(stoi)) );
1646  SCIP_CALL( setScenarioNum(scip, scenario, numscenarios) );
1647  SCIP_CALL( setScenarioStageNum(scip, scenario, SCIPtimFindStage(scip, stoinputField5(stoi))) );
1648  SCIP_CALL( setScenarioProbability(scip, scenario, atof(stoinputField4(stoi))) );
1649 
1650  numscenarios++;
1651  addscenario = TRUE;
1652  }
1653  else
1654  {
1655  SCIP_CALL( addScenarioEntry(scip, scenario, stoinputField2(stoi), stoinputField1(stoi),
1656  atof(stoinputField3(stoi))) );
1657  }
1658  }
1659  stoinputSyntaxerror(stoi);
1660 
1661 TERMINATE:
1662 
1663  return SCIP_OKAY;
1664 }
1665 
1666 
1667 /** Process INDEP section. */
1668 static
1670  STOINPUT* stoi, /**< sto input structure */
1671  SCIP* scip, /**< SCIP data structure */
1672  SCIP_READERDATA* readerdata /**< the reader data */
1673  )
1674 {
1675  STOSCENARIO*** blocks;
1676  int numblocks;
1677  int* numblocksperblock;
1678  int blockssize;
1679  int* blocksperblocksize;
1680  int blocknum;
1681  int blockindex;
1682  int i;
1683  int j;
1684  char stagenames[SCIP_MAXSTRLEN];
1685  int numstages;
1686  SCIP_Bool foundblock;
1687 
1688  SCIP_Real probability;
1689  char currstagename[SCIP_MAXSTRLEN];
1690 
1691  SCIPdebugMsg(scip, "read Indep\n");
1692 
1693  /* This has to be the Line with the name. */
1694  if( stoinputField1(stoi) == NULL )
1695  {
1696  stoinputSyntaxerror(stoi);
1697  return SCIP_OKAY;
1698  }
1699 
1700  stoinputSetStochtype(stoi, stoinputField1(stoi));
1701 
1702  /* initializing the block data */
1703  numblocks = 0;
1704  blockssize = STO_DEFAULT_ARRAYSIZE;
1706  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &numblocksperblock, STO_DEFAULT_ARRAYSIZE) );
1707  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &blocksperblocksize, STO_DEFAULT_ARRAYSIZE) );
1708 
1709  /* initializing the stage names record */
1710  numstages = 0;
1711  (void) SCIPsnprintf(stagenames, SCIP_MAXSTRLEN, "");
1712 
1713  while( stoinputReadLine(stoi) )
1714  {
1715  if( stoinputField0(stoi) != NULL )
1716  {
1717  if( !strcmp(stoinputField0(stoi), "INDEP") )
1718  {
1720  }
1721  else if( !strcmp(stoinputField0(stoi), "ENDATA") )
1722  {
1723  SCIP_CALL( createScenariosFromBlocks(scip, readerdata, blocks, numblocks, numblocksperblock, numstages) );
1725  }
1726  else
1727  stoinputSyntaxerror(stoi);
1728 
1729  goto TERMINATE;
1730  }
1731 
1732  /* if the 5th input is NULL, then the 4th input is the probability. Otherwise, the 4th input is the stage name and
1733  * the 5th input is the probability. The stage name is redundant information, but sometimes included for more
1734  * information.
1735  */
1736  if( stoinputField5(stoi) == NULL )
1737  {
1738  probability = atof(stoinputField4(stoi));
1739  (void) SCIPsnprintf(currstagename, SCIP_MAXSTRLEN, "%s", SCIPtimConsGetStageName(scip, stoinputField2(stoi)));
1740  }
1741  else
1742  {
1743  probability = atof(stoinputField5(stoi));
1744  (void) SCIPsnprintf(currstagename, SCIP_MAXSTRLEN, "%s", stoinputField4(stoi));
1745  }
1746 
1747  /* checking whether the stage has been added previously */
1748  if( strstr(stagenames, currstagename) == NULL )
1749  {
1750  /* recording the stage name as processed */
1751  (void) SCIPsnprintf(stagenames, SCIP_MAXSTRLEN, "%s_%s", stagenames, currstagename);
1752 
1753  numstages++;
1754  }
1755 
1756  foundblock = FALSE;
1757 
1758  /* determining whether a block name has previously been added */
1759  for( i = 0; i < numblocks; i++ )
1760  {
1761  if( strcmp(getScenarioName(blocks[i][0]), stoinputField2(stoi)) == 0 )
1762  {
1763  foundblock = TRUE;
1764  break;
1765  }
1766  }
1767  blocknum = i;
1768 
1769  /* if the block is found, then the memory for the blocks array must be ensured */
1770  if( foundblock )
1771  {
1772  /* ensuring enough memory is available for the blocks */
1773  if( numblocksperblock[blocknum] + 1 > blocksperblocksize[blocknum] )
1774  {
1775  int newsize;
1776  newsize = SCIPcalcMemGrowSize(scip, numblocksperblock[blocknum] + 1);
1777  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &blocks[blocknum], blocksperblocksize[blocknum], newsize) ); /*lint !e866*/
1778  blocksperblocksize[blocknum] = newsize;
1779  }
1780  }
1781  else
1782  {
1783  /* ensuring enough memory is available for the blocks */
1784  if( numblocks + 1 > blockssize )
1785  {
1786  int newsize;
1787  newsize = SCIPcalcMemGrowSize(scip, numblocks + 1);
1788  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &blocks, blockssize, newsize) );
1789  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &numblocksperblock, blockssize, newsize) );
1790  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &blocksperblocksize, blockssize, newsize) );
1791  blockssize = newsize;
1792  }
1793 
1794  blocksperblocksize[blocknum] = STO_DEFAULT_BLOCKARRAYSIZE;
1795  numblocksperblock[blocknum] = 0;
1796  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &blocks[blocknum], blocksperblocksize[blocknum]) );
1797  }
1798 
1799  blockindex = numblocksperblock[blocknum];
1800 
1801  /* creating the scenario data structure */
1802  SCIP_CALL( createScenarioData(scip, &blocks[blocknum][blockindex]) );
1803 
1804  SCIP_CALL( setScenarioName(scip, blocks[blocknum][blockindex], stoinputField2(stoi)) );
1805  SCIP_CALL( setScenarioStageName(scip, blocks[blocknum][blockindex], currstagename) );
1806  SCIP_CALL( setScenarioProbability(scip, blocks[blocknum][blockindex], probability) );
1807  numblocksperblock[blocknum]++;
1808 
1809  if( !foundblock )
1810  numblocks++;
1811 
1812  SCIP_CALL( addScenarioEntry(scip, blocks[blocknum][blockindex], stoinputField2(stoi), stoinputField1(stoi),
1813  atof(stoinputField3(stoi))) );
1814  }
1815  stoinputSyntaxerror(stoi);
1816 
1817 TERMINATE:
1818 
1819  /* releasing the scenario data */
1820  for( i = numblocks - 1; i >= 0; i-- )
1821  {
1822  for( j = numblocksperblock[i] - 1; j >= 0; j-- )
1823  SCIP_CALL( freeScenarioTree(scip, &blocks[i][j]) );
1824  }
1825 
1826  for( i = numblocks - 1; i >= 0; i-- )
1827  SCIPfreeBlockMemoryArray(scip, &blocks[i], blocksperblocksize[i]);
1828  SCIPfreeBlockMemoryArray(scip, &blocksperblocksize, blockssize);
1829  SCIPfreeBlockMemoryArray(scip, &numblocksperblock, blockssize);
1830  SCIPfreeBlockMemoryArray(scip, &blocks, blockssize);
1831 
1832  return SCIP_OKAY;
1833 }
1834 
1835 
1836 /** computes the probability of a scenario */
1837 static
1839  SCIP* scip, /**< the SCIP data structure */
1840  STOSCENARIO* scenario /**< the current scenario */
1841  )
1842 {
1843  STOSCENARIO* checkscen;
1844  SCIP_Real probability;
1845 
1846  assert(scip != NULL);
1847  assert(scenario != NULL);
1848 
1849  /* computing the probability for the scenario */
1850  checkscen = scenario;
1851  probability = 1;
1852  while( checkscen != NULL )
1853  {
1854  probability *= getScenarioProbability(scip, checkscen);
1855  checkscen = getScenarioParent(checkscen);
1856  }
1857 
1858  return probability;
1859 }
1860 
1861 /** gets the variable name */
1862 static
1864  char* name, /**< the name to be returned */
1865  const char* varname, /**< the root of the variable name */
1866  int stagenum, /**< the stage number */
1867  int scenarionum /**< the scenario number */
1868  )
1869 {
1870  if( stagenum < 0 )
1871  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_00_%d", varname, scenarionum);
1872  else
1873  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_%d_%d", varname, stagenum, scenarionum);
1874 }
1875 
1876 
1877 /** add variables to the scenario */
1878 static
1880  SCIP* scip, /**< the SCIP data structure */
1881  STOSCENARIO* scenario, /**< the current scenario */
1882  SCIP_VAR** vars, /**< the variables of the core problem associated with this scenario */
1883  int nvars /**< the number of variables for this scenario */
1884  )
1885 {
1886  SCIP_Real probability;
1887  int i;
1888  char name[SCIP_MAXSTRLEN];
1889 
1890  assert(scip != NULL);
1891  assert(scenario != NULL);
1892  assert(vars != NULL);
1893 
1894  /* computing the probability for the scenario */
1895  probability = computeScenarioProbability(scip, scenario);
1896 
1897  for( i = 0; i < nvars; i++ )
1898  {
1899  SCIP_VAR* var;
1900  SCIP_Real obj;
1901  SCIP_VARTYPE vartype;
1902 
1903  SCIPdebugMessage("Original problem variable <%s> is being duplicated for scenario %d\n", SCIPvarGetName(vars[i]),
1904  getScenarioNum(scip, scenario));
1905 
1906  if( SCIPvarIsDeleted(vars[i]) )
1907  continue;
1908 
1909  obj = SCIPvarGetObj(vars[i])*probability;
1910 
1911  vartype = SCIPvarGetType(vars[i]);
1912 #if 0
1913  if( getScenarioStageNum(scip, scenario) == 0 )
1914  vartype = SCIPvarGetType(vars[i]);
1915  else
1916  vartype = SCIP_VARTYPE_CONTINUOUS;
1917 #endif
1918 
1919  /* creating a variable as a copy of the original variable. */
1920  getScenarioEntityName(name, SCIPvarGetName(vars[i]), getScenarioStageNum(scip, scenario), getScenarioNum(scip, scenario));
1921  SCIP_CALL( SCIPcreateVar(scip, &var, name, SCIPvarGetLbOriginal(vars[i]), SCIPvarGetUbOriginal(vars[i]),
1922  obj, vartype, SCIPvarIsInitial(vars[i]), SCIPvarIsRemovable(vars[i]), NULL, NULL, NULL,
1923  NULL, NULL) );
1924 
1925  SCIPdebugMessage("Adding variable <%s>\n", name);
1926 
1927  SCIP_CALL( SCIPaddVar(scip, var) );
1928  SCIP_CALL( SCIPreleaseVar(scip, &var) );
1929  }
1930 
1931  return SCIP_OKAY;
1932 }
1933 
1934 
1935 /** finds the scenario variable to add to a constraint */
1936 static
1938  SCIP* scip, /**< the SCIP data structure */
1939  STOSCENARIO* scenario, /**< the current scenario */
1940  SCIP_VAR* consvar, /**< the variable in the constraint that is being searched for */
1941  SCIP_VAR** scenariovar /**< pointer to return the variable to be added to the constraint */
1942  )
1943 {
1944  STOSCENARIO* checkscen;
1945  char varname[SCIP_MAXSTRLEN];
1946 
1947  assert(scip != NULL);
1948  assert(scenario != NULL);
1949  assert(consvar != NULL);
1950  assert(scenariovar != NULL);
1951 
1952  (*scenariovar) = NULL;
1953 
1954  checkscen = scenario;
1955 
1956  /* NOTE: if the variable does not exist, then we need to search the preceding scenarios. In the case of
1957  * decomposition, then we only check the preceding scenario. As such, a check count is used to limit the number
1958  * of scenario checks. */
1959  while( (*scenariovar) == NULL )
1960  {
1961  assert(checkscen != NULL);
1962  if( getScenarioStageNum(scip, checkscen) == 0 )
1963  (void) SCIPsnprintf(varname, SCIP_MAXSTRLEN, "%s", SCIPvarGetName(consvar));
1964  else
1965  getScenarioEntityName(varname, SCIPvarGetName(consvar), getScenarioStageNum(scip, checkscen),
1966  getScenarioNum(scip, checkscen));
1967 
1968  (*scenariovar) = SCIPfindVar(scip, varname);
1969 
1970  checkscen = getScenarioParent(checkscen);
1971  }
1972  assert((*scenariovar) != NULL);
1973 
1974  return SCIP_OKAY;
1975 }
1976 
1977 
1978 /** create variable for the decomposed scenario */
1979 static
1981  SCIP* scip, /**< the SCIP data structure */
1982  STOSCENARIO* scenario, /**< the current scenario */
1983  SCIP_VAR* consvar, /**< the variable in the constraint that is being searched for */
1984  SCIP_VAR** scenariovar, /**< pointer to return the variable to be added to the constraint */
1985  SCIP_Bool* varadded /**< pointer to indicate whether a variable has been added */
1986  )
1987 {
1988  STOSCENARIO* checkscen;
1989  SCIP_VAR* searchvar;
1990  int checkcount;
1991  char varname[SCIP_MAXSTRLEN];
1992 
1993  assert(scip != NULL);
1994  assert(scenario != NULL);
1995  assert(consvar != NULL);
1996 
1997  (*varadded) = FALSE;
1998 
1999  /* finding the scenario that the consvar belongs to */
2000  checkscen = scenario;
2001  searchvar = NULL;
2002  checkcount = 0;
2003  while( searchvar == NULL && checkcount < 2 )
2004  {
2005  assert(checkscen != NULL);
2006  if( getScenarioStageNum(scip, checkscen) == 0 )
2007  (void) SCIPsnprintf(varname, SCIP_MAXSTRLEN, "%s", SCIPvarGetName(consvar));
2008  else
2009  getScenarioEntityName(varname, SCIPvarGetName(consvar), getScenarioStageNum(scip, checkscen),
2010  getScenarioNum(scip, checkscen));
2011 
2012  /* first checking whether the variable is included in the scenario */
2013  searchvar = SCIPfindVar(scip, varname);
2014  if( searchvar != NULL )
2015  {
2016  (*scenariovar) = searchvar;
2017  return SCIP_OKAY;
2018  }
2019 
2020  searchvar = SCIPfindVar(getScenarioScip(checkscen), varname);
2021 
2022  checkscen = getScenarioParent(checkscen);
2023  checkcount++;
2024  }
2025 
2026  if( searchvar != NULL )
2027  {
2028  SCIP_VAR* var;
2029  /* creating a variable as a copy of the original variable. */
2030  SCIP_CALL( SCIPcreateVar(scip, &var, varname, SCIPvarGetLbOriginal(searchvar), SCIPvarGetUbOriginal(searchvar),
2031  0.0, SCIPvarGetType(searchvar), SCIPvarIsInitial(searchvar), SCIPvarIsRemovable(searchvar), NULL, NULL,
2032  NULL, NULL, NULL) );
2033 
2034  SCIP_CALL( SCIPaddVar(scip, var) );
2035 
2036  (*scenariovar) = var;
2037  (*varadded) = TRUE;
2038  }
2039 
2040  return SCIP_OKAY;
2041 }
2042 
2043 
2044 /** adds the constraint to the scenario problem */
2045 static
2047  SCIP* scip, /**< the SCIP data structure */
2048  STOSCENARIO* scenario, /**< the current scenario */
2049  SCIP_CONS** conss, /**< the constraints of the core problem associated with this scenario */
2050  int nconss, /**< the number of constraints for this scenario */
2051  SCIP_Bool decomp /**< is the problem being decomposed */
2052  )
2053 {
2054  int i;
2055  int j;
2056  char name[SCIP_MAXSTRLEN];
2057  SCIP_Bool varadded;
2058 
2059  assert(scip != NULL);
2060  assert(scenario != NULL);
2061  assert(conss != NULL);
2062 
2063  /* Add constraints */
2064  /* NOTE: It is assumed that the problems only have linear constraints */
2065  for( i = 0; i < nconss; i++ )
2066  {
2067  SCIP_CONS* cons;
2068  SCIP_VAR** consvars;
2069  SCIP_Real* consvals;
2070  int nconsvars;
2071 
2072  if( SCIPconsIsDeleted(conss[i]) )
2073  continue;
2074 
2075  /* creating a linear constraint as a copy of the original constraint. */
2076  getScenarioEntityName(name, SCIPconsGetName(conss[i]), getScenarioStageNum(scip, scenario), getScenarioNum(scip, scenario));
2077  SCIP_CALL( SCIPcreateConsLinear(scip, &cons, name, 0, NULL, NULL, SCIPgetLhsLinear(scip, conss[i]),
2078  SCIPgetRhsLinear(scip, conss[i]), SCIPconsIsInitial(conss[i]), SCIPconsIsSeparated(conss[i]),
2079  SCIPconsIsEnforced(conss[i]), SCIPconsIsChecked(conss[i]), SCIPconsIsMarkedPropagate(conss[i]),
2080  SCIPconsIsLocal(conss[i]), SCIPconsIsModifiable(conss[i]), SCIPconsIsDynamic(conss[i]),
2081  SCIPconsIsRemovable(conss[i]), SCIPconsIsStickingAtNode(conss[i])) );
2082 
2083  consvars = SCIPgetVarsLinear(scip, conss[i]);
2084  consvals = SCIPgetValsLinear(scip, conss[i]);
2085  nconsvars = SCIPgetNVarsLinear(scip, conss[i]);
2086 
2087  for( j = 0; j < nconsvars; j++ )
2088  {
2089  SCIP_VAR* scenariovar;
2090 
2091  scenariovar = NULL;
2092 
2093  varadded = FALSE;
2094 
2095  if( decomp )
2096  SCIP_CALL( getScenarioDecompVar(scip, scenario, consvars[j], &scenariovar, &varadded) );
2097  else
2098  SCIP_CALL( findScenarioVar(scip, scenario, consvars[j], &scenariovar) );
2099 
2100  if( scenariovar != NULL )
2101  SCIP_CALL( SCIPaddCoefLinear(scip, cons, scenariovar, consvals[j]) );
2102 
2103  if( varadded )
2104  SCIP_CALL( SCIPreleaseVar(scip, &scenariovar) );
2105  }
2106 
2107  SCIP_CALL( SCIPaddCons(scip, cons) );
2108  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
2109  }
2110 
2111  return SCIP_OKAY;
2112 }
2113 
2114 /** add variables and constraint to problem */
2115 static
2117  SCIP* scip, /**< the SCIP data structure of master problem */
2118  STOSCENARIO* scenario, /**< the current scenario */
2119  SCIP_Bool decomp /**< is the problem being decomposed */
2120  )
2121 {
2122  SCIP* scenarioscip;
2123  SCIP_CONS** conss;
2124  SCIP_VAR** vars;
2125  SCIP_Real probability;
2126  int nconss;
2127  int nvars;
2128  int nentries;
2129  int stagenum;
2130  int i;
2131  char name[SCIP_MAXSTRLEN];
2132 
2133  assert(scip != NULL);
2134  assert(scenario != NULL);
2135 
2136  stagenum = SCIPtimFindStage(scip, getScenarioStageName(scip, scenario));
2137  assert(stagenum >= 0 && stagenum < SCIPtimGetNStages(scip));
2138 
2139  SCIPdebugMessage("Creating scenario at stage <%d>. Scenario: %d Stage: %d\n", stagenum, getScenarioNum(scip, scenario),
2140  getScenarioStageNum(scip, scenario));
2141 
2142  conss = SCIPtimGetStageConss(scip, stagenum);
2143  nconss = SCIPtimGetStageNConss(scip, stagenum);
2144  vars = SCIPtimGetStageVars(scip, stagenum);
2145  nvars = SCIPtimGetStageNVars(scip, stagenum);
2146 
2147  /* this if 0 will be removed when the stochastic reader is merged with the Benders' branch */
2148  if( decomp )
2149  {
2150  SCIP_CALL( SCIPcreate(&scenarioscip) );
2151 
2152  getScenarioEntityName(name, SCIPgetProbName(scip), getScenarioStageNum(scip, scenario), getScenarioNum(scip, scenario));
2153 
2154  /* creating the problem */
2155  SCIP_CALL( SCIPcreateProbBasic(scenarioscip, name) );
2156 
2157  /* we explicitly enable the use of a debug solution for this main SCIP instance */
2158  SCIPenableDebugSol(scenarioscip);
2159 
2160  /* include default SCIP plugins */
2161  SCIP_CALL( SCIPincludeDefaultPlugins(scenarioscip) );
2162 
2163  /* activating the Benders' constraint handler for the scenario stages.
2164  * TODO: consider whether the two-phase method should be activated by default in the scenario stages.
2165  */
2166  SCIP_CALL( SCIPsetBoolParam(scenarioscip, "constraints/benders/active", TRUE) );
2167 
2168  /* allocating memory for the subproblems */
2169  if( getScenarioNChildren(scenario) > 0 )
2170  SCIP_CALL( createScenarioSubproblemArray(scenarioscip, scenario) );
2171  }
2172  else
2173  scenarioscip = scip;
2174 
2175  /* adding the scenarioscip to the scenario */
2176  setScenarioScip(scenario, scenarioscip);
2177 
2178  /* adding the variables to the scenario */
2179  SCIP_CALL( addScenarioVarsToProb(scenarioscip, scenario, vars, nvars) );
2180 
2181  /* adding the constraints to the scenario */
2182  SCIP_CALL( addScenarioConsToProb(scenarioscip, scenario, conss, nconss, decomp) );
2183 
2184  /* add the variables and constraints of the child scenarios */
2185  for( i = 0; i < getScenarioNChildren(scenario); i++ )
2186  {
2187  /* the master SCIP is always passed to the recursive function. The scenario SCIP instances are generated in the
2188  * function call. */
2189  SCIP_CALL( addScenarioVarsAndConsToProb(scip, getScenarioChild(scenario, i), decomp) );
2190  if( decomp )
2191  addScenarioSubproblem(scenario, getScenarioScip(getScenarioChild(scenario, i)));
2192  }
2193 
2194  /* adding the Benders' decomposition */
2195  if( decomp && getScenarioNChildren(scenario) > 0 )
2197 
2198  /* computing the probability for the scenario */
2199  probability = computeScenarioProbability(scenarioscip, scenario);
2200 
2201  /* change the constraints for the given scenario */
2202  nentries = getScenarioNEntries(scenario);
2203  for( i = 0; i < nentries; i++ )
2204  {
2205  SCIP_CONS* cons;
2206  SCIP_VAR* var;
2207  char RHS[] = "RHS";
2208  char RIGHT[] = "RIGHT";
2209  char MINI[] = "MINI";
2210  char obj[] = "obj";
2211  char OBJ[] = "OBJ";
2212 
2213  /* finding the constraint associated with the row */
2214  getScenarioEntityName(name, getScenarioEntryRow(scenario, i), getScenarioStageNum(scenarioscip, scenario),
2215  getScenarioNum(scenarioscip, scenario));
2216  cons = SCIPfindCons(scenarioscip, name);
2217 
2218  if( strncmp(getScenarioEntryCol(scenario, i), RHS, 3) == 0 || strcmp(getScenarioEntryCol(scenario, i), RIGHT) == 0 )
2219  {
2220  /* if the constraint is an equality constraint, then the LHS must also be changed */
2221  if( SCIPgetLhsLinear(scenarioscip, cons) >= SCIPgetRhsLinear(scenarioscip, cons) )
2222  {
2223  SCIP_CALL( SCIPchgLhsLinear(scenarioscip, cons, getScenarioEntryValue(scenario, i)) );
2224  SCIP_CALL( SCIPchgRhsLinear(scenarioscip, cons, getScenarioEntryValue(scenario, i)) );
2225  }
2226  else if( SCIPisLT(scenarioscip, SCIPgetRhsLinear(scenarioscip, cons), SCIPinfinity(scenarioscip)) )
2227  SCIP_CALL( SCIPchgRhsLinear(scenarioscip, cons, getScenarioEntryValue(scenario, i)) );
2228  else if( SCIPisLT(scenarioscip, SCIPgetLhsLinear(scenarioscip, cons), SCIPinfinity(scenarioscip)) )
2229  SCIP_CALL( SCIPchgLhsLinear(scenarioscip, cons, getScenarioEntryValue(scenario, i)) );
2230  }
2231  else if( strstr(getScenarioEntryRow(scenario, i), MINI) != NULL ||
2232  strstr(getScenarioEntryRow(scenario, i), obj) != NULL ||
2233  strstr(getScenarioEntryRow(scenario, i), OBJ) != NULL )
2234  {
2235  /* finding the variable associated with the column */
2236  getScenarioEntityName(name, getScenarioEntryCol(scenario, i), getScenarioStageNum(scenarioscip, scenario),
2237  getScenarioNum(scenarioscip, scenario));
2238  var = SCIPfindVar(scenarioscip, name);
2239 
2240  /* changing the coefficient for the variable */
2241  SCIP_CALL( SCIPchgVarObj(scenarioscip, var, getScenarioEntryValue(scenario, i)*probability) );
2242  }
2243  else
2244  {
2245  /* finding the variable associated with the column */
2246  getScenarioEntityName(name, getScenarioEntryCol(scenario, i), getScenarioStageNum(scenarioscip, scenario),
2247  getScenarioNum(scenarioscip, scenario));
2248  var = SCIPfindVar(scenarioscip, name);
2249 
2250  if( var == NULL )
2251  {
2252  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s", getScenarioEntryCol(scenario, i));
2253  var = SCIPfindVar(scenarioscip, name);
2254  }
2255 
2256  /* changing the coefficient for the variable */
2257  SCIP_CALL( SCIPchgCoefLinear(scenarioscip, cons, var, getScenarioEntryValue(scenario, i)) );
2258  }
2259  }
2260 
2261  return SCIP_OKAY;
2262 }
2263 
2264 /** removes the core variables and constriants for stage 2 and lower */
2265 static
2267  SCIP* scip /**< the SCIP data structure */
2268  )
2269 {
2270  SCIP_CONS** conss;
2271  SCIP_VAR** vars;
2272  int nconss;
2273  int nvars;
2274  int numstages;
2275  int i;
2276  int j;
2277  SCIP_Bool deleted;
2278 
2279  assert(scip != NULL);
2280 
2281  numstages = SCIPtimGetNStages(scip);
2282 
2283  /* looping through all stages to remove the variables and constraints. The first stage is not removed as these are
2284  * part of the complete problem */
2285  for( i = 1; i < numstages; i++ )
2286  {
2287  conss = SCIPtimGetStageConss(scip, i);
2288  vars = SCIPtimGetStageVars(scip, i);
2289  nconss = SCIPtimGetStageNConss(scip, i);
2290  nvars = SCIPtimGetStageNVars(scip, i);
2291 
2292  /* removing constriants */
2293  for( j = 0; j < nconss; j++ )
2294  {
2295  if( !SCIPconsIsDeleted(conss[j]) )
2296  SCIP_CALL( SCIPdelCons(scip, conss[j]) );
2297  }
2298 
2299  /* removing variables */
2300  for( j = 0; j < nvars; j++ )
2301  {
2302  if( !SCIPvarIsDeleted(vars[j]) )
2303  {
2304  SCIP_CALL( SCIPdelVar(scip, vars[j], &deleted) );
2305  assert(deleted);
2306  }
2307  }
2308  }
2309 
2310  return SCIP_OKAY;
2311 }
2312 
2313 
2314 /* build the stochastic program completely as a MIP, i.e. no decomposition */
2315 static
2317  SCIP* scip, /**< the SCIP data structure */
2318  SCIP_READERDATA* readerdata /**< the reader data */
2319  )
2320 {
2321  int i;
2322 
2323  assert(scip != NULL);
2324  assert(readerdata != NULL);
2325 
2326  /* adding all variables and constraints for stages below the first stage.
2327  * The first stage is covered by the original problem. */
2328  for( i = 0; i < getScenarioNChildren(readerdata->scenariotree); i++ )
2329  SCIP_CALL( addScenarioVarsAndConsToProb(scip, getScenarioChild(readerdata->scenariotree, i), FALSE) );
2330 
2331  /* removing the variable and constraints that were included as part of the core file */
2333 
2334  return SCIP_OKAY;
2335 }
2336 
2337 
2338 /** builds the stochastic program using Benders' decomposition */
2339 static
2341  SCIP* scip, /**< the SCIP data structure */
2342  SCIP_READERDATA* readerdata /**< the reader data */
2343  )
2344 {
2345  int i;
2346 
2347  assert(scip != NULL);
2348  assert(readerdata != NULL);
2349 
2350  SCIP_CALL( createScenarioSubproblemArray(scip, readerdata->scenariotree) );
2351 
2352  /* activating the Benders' constraint handler. The two-phase method is activated by default. If the user desires not
2353  * to use the two-phase method, then the setting in cons_benderslp must be explicitly changed.
2354  */
2355  SCIP_CALL( SCIPsetBoolParam(scip, "constraints/benders/active", TRUE) );
2356  SCIP_CALL( SCIPsetBoolParam(scip, "constraints/benderslp/active", TRUE) );
2357 
2358  setScenarioScip(readerdata->scenariotree, scip);
2359 
2360  /* adding all variables and constraints for stages below the first stage.
2361  * The first stage is covered by the original problem. */
2362  for( i = 0; i < getScenarioNChildren(readerdata->scenariotree); i++ )
2363  {
2364  SCIP_CALL( addScenarioVarsAndConsToProb(scip, getScenarioChild(readerdata->scenariotree, i), TRUE) );
2365  addScenarioSubproblem(readerdata->scenariotree, getScenarioScip(getScenarioChild(readerdata->scenariotree, i)));
2366  }
2367 
2368  /* creating the Benders' decomposition */
2369  SCIP_CALL( SCIPcreateBendersDefault(scip, getScenarioSubproblemArray(readerdata->scenariotree),
2370  getScenarioNChildren(readerdata->scenariotree)) );
2371 
2372  /* removing the variable and constraints that were included as part of the core file */
2374 
2375  /* changing settings that are required for Benders' decomposition */
2377  SCIP_CALL( SCIPsetIntParam(scip, "constraints/benders/maxprerounds", 1) );
2378  SCIP_CALL( SCIPsetIntParam(scip, "presolving/maxrounds", 1) );
2379  SCIP_CALL( SCIPsetIntParam(scip, "propagating/maxrounds", 0) );
2380  SCIP_CALL( SCIPsetIntParam(scip, "propagating/maxroundsroot", 0) );
2381  SCIP_CALL( SCIPsetIntParam(scip, "heuristics/trysol/freq", 1) );
2382 
2383  SCIP_CALL( SCIPsetIntParam(scip, "benders/default/lnsmaxdepth", 10) );
2384 
2385  return SCIP_OKAY;
2386 }
2387 
2388 /** Read the stochastic information of an SMPS file instance in "STO File Format". */
2389 static
2391  SCIP* scip, /**< SCIP data structure */
2392  const char* filename, /**< name of the input file */
2393  SCIP_READERDATA* readerdata /**< the reader data */
2394  )
2395 {
2396  SCIP_FILE* fp;
2397  STOINPUT* stoi;
2398  SCIP_RETCODE retcode;
2399  SCIP_Bool error = TRUE;
2400  SCIP_Bool unsupported = FALSE;
2401 
2402  assert(scip != NULL);
2403  assert(filename != NULL);
2404 
2405  fp = SCIPfopen(filename, "r");
2406  if( fp == NULL )
2407  {
2408  SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
2409  SCIPprintSysError(filename);
2410  return SCIP_NOFILE;
2411  }
2412 
2413  SCIP_CALL_FINALLY( stoinputCreate(scip, &stoi, fp), SCIPfclose(fp) );
2414  SCIP_CALL_TERMINATE( retcode, createReaderdata(scip, readerdata), TERMINATE );
2415 
2416  SCIP_CALL_TERMINATE( retcode, readStoch(scip, stoi), TERMINATE );
2417 
2418  /* checking for supported stochastic information types */
2420  {
2421  SCIPinfoMessage(scip, NULL, "\nSorry, currently only STO files with the stochastic information as DISCRETE are supported.\n\n");
2422  SCIPinfoMessage(scip, NULL, "NOTE: The problem provided by the COR file is loaded without stochastic information.\n\n");
2423  unsupported = TRUE;
2424  }
2425  else
2426  {
2427  if( stoinputSection(stoi) == STO_BLOCKS )
2428  {
2429  SCIP_CALL_TERMINATE( retcode, readBlocks(stoi, scip, readerdata), TERMINATE );
2430  }
2431 
2432  if( stoinputSection(stoi) == STO_SCENARIOS )
2433  {
2434  /* if there are more than two stages, then the sto file is not read. */
2435  if( SCIPtimGetNStages(scip) > 2 )
2436  {
2437  SCIPinfoMessage(scip, NULL, "\nThe scenarios for the stochastic programs are defined in <%s> as SCENARIOS\n", filename);
2438  SCIPinfoMessage(scip, NULL, "Sorry, currently only two-stage stochastic programs are supported when scenarios are defined as SCENARIOS.\n\n");
2439  SCIPinfoMessage(scip, NULL, "NOTE: The problem provided by the COR file is loaded without stochastic information.\n\n");
2440  unsupported = TRUE;
2441  }
2442  else
2443  {
2444  SCIP_CALL_TERMINATE( retcode, readScenarios(stoi, scip, readerdata), TERMINATE );
2445  }
2446  }
2447 
2448  if( stoinputSection(stoi) == STO_INDEP )
2449  {
2450  SCIP_CALL_TERMINATE( retcode, readIndep(stoi, scip, readerdata), TERMINATE );
2451  }
2452  }
2453 
2454  if( !unsupported && stoinputSection(stoi) != STO_ENDATA )
2455  stoinputSyntaxerror(stoi);
2456 
2457  error = stoinputHasError(stoi);
2458 
2459  if( !error && !unsupported )
2460  {
2461  if( readerdata->usebenders )
2462  {
2463  SCIP_CALL_TERMINATE( retcode, buildDecompProblem(scip, readerdata), TERMINATE );
2464  }
2465  else
2466  {
2467  SCIP_CALL_TERMINATE( retcode, buildFullProblem(scip, readerdata), TERMINATE );
2468  }
2469  }
2470 
2471 /* cppcheck-suppress unusedLabel */
2472 TERMINATE:
2473  stoinputFree(scip, &stoi);
2474  SCIPfclose(fp);
2475 
2476  if( error )
2477  return SCIP_READERROR;
2478  else
2479  return SCIP_OKAY;
2480 }
2481 
2482 
2483 /*
2484  * Callback methods of reader
2485  */
2486 
2487 /** copy method for reader plugins (called when SCIP copies plugins) */
2488 static
2489 SCIP_DECL_READERCOPY(readerCopySto)
2490 { /*lint --e{715}*/
2491  assert(scip != NULL);
2492  assert(reader != NULL);
2493  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
2494 
2495  /* call inclusion method of reader */
2497 
2498  return SCIP_OKAY;
2499 }
2500 
2501 /** destructor of reader to free user data (called when SCIP is exiting) */
2502 static
2503 SCIP_DECL_READERFREE(readerFreeSto)
2504 {
2505  SCIP_READERDATA* readerdata;
2506 
2507  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
2508  readerdata = SCIPreaderGetData(reader);
2509  assert(readerdata != NULL);
2510 
2511  SCIP_CALL( freeReaderdata(scip, readerdata) );
2512 
2513  return SCIP_OKAY;
2514 }
2515 
2516 /** problem reading method of reader */
2517 static
2518 SCIP_DECL_READERREAD(readerReadSto)
2519 { /*lint --e{715}*/
2520  SCIP_READER* correader;
2521  SCIP_READER* timreader;
2522 
2523  assert(reader != NULL);
2524  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
2525 
2526  correader = SCIPfindReader(scip, "correader");
2527  timreader = SCIPfindReader(scip, "timreader");
2528 
2529  if( correader == NULL )
2530  {
2531  SCIPwarningMessage(scip, "It is necessary to include the \"cor\" reader\n");
2532  (*result) = SCIP_DIDNOTRUN;
2533  return SCIP_OKAY;
2534  }
2535 
2536  if( timreader == NULL )
2537  {
2538  SCIPwarningMessage(scip, "It is necessary to include the \"tim\" reader\n");
2539  (*result) = SCIP_DIDNOTRUN;
2540  return SCIP_OKAY;
2541  }
2542 
2543  /* checking whether the cor file has been read */
2544  if( !SCIPcorHasRead(correader) )
2545  {
2546  SCIPwarningMessage(scip, "The core file must be read before the time and stochastic files.\n");
2547  (*result) = SCIP_DIDNOTRUN;
2548  return SCIP_OKAY;
2549  }
2550 
2551  /* checking whether the tim file has been read */
2552  if( !SCIPtimHasRead(timreader) )
2553  {
2554  SCIPwarningMessage(scip, "The time file must be read before the stochastic files.\n");
2555  (*result) = SCIP_DIDNOTRUN;
2556  return SCIP_OKAY;
2557  }
2558 
2559  SCIP_CALL( SCIPreadSto(scip, filename, result) );
2560 
2561  return SCIP_OKAY;
2562 }
2563 
2564 /*
2565  * sto file reader specific interface methods
2566  */
2567 
2568 /** includes the sto file reader in SCIP */
2570  SCIP* scip /**< SCIP data structure */
2571  )
2572 {
2573  SCIP_READERDATA* readerdata;
2574  SCIP_READER* reader;
2575 
2576  /* create reader data */
2577  SCIP_CALL( SCIPallocBlockMemory(scip, &readerdata) );
2578  readerdata->scenariotree = NULL;
2579  readerdata->numscenarios = 0;
2580 
2581  /* include reader */
2582  SCIP_CALL( SCIPincludeReaderBasic(scip, &reader, READER_NAME, READER_DESC, READER_EXTENSION, readerdata) );
2583 
2584  /* set non fundamental callbacks via setter functions */
2585  SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopySto) );
2586  SCIP_CALL( SCIPsetReaderFree(scip, reader, readerFreeSto) );
2587  SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadSto) );
2588 
2589  /* add decomposition parameters */
2591  "reading/" READER_NAME "/usebenders",
2592  "should Benders' decomposition be used?",
2593  &readerdata->usebenders, FALSE, DEFAULT_USEBENDERS, NULL, NULL) );
2594 
2595  return SCIP_OKAY;
2596 }
2597 
2598 
2599 /** reads the stochastic information for a stochastic program that is in SMPS format */
2601  SCIP* scip, /**< SCIP data structure */
2602  const char* filename, /**< full path and name of file to read, or NULL if stdin should be used */
2603  SCIP_RESULT* result /**< pointer to store the result of the file reading call */
2604  )
2605 {
2606  SCIP_READER* reader;
2607  SCIP_READERDATA* readerdata;
2608  SCIP_RETCODE retcode;
2609 
2610  assert(scip != NULL);
2611  assert(result != NULL);
2612 
2613  reader = SCIPfindReader(scip, READER_NAME);
2614  assert(reader != NULL);
2615  readerdata = SCIPreaderGetData(reader);
2616 
2617  retcode = readSto(scip, filename, readerdata);
2618 
2619  if( retcode == SCIP_PLUGINNOTFOUND )
2620  retcode = SCIP_READERROR;
2621 
2622  if( retcode == SCIP_NOFILE || retcode == SCIP_READERROR )
2623  return retcode;
2624 
2625  SCIP_CALL( retcode );
2626 
2627  *result = SCIP_SUCCESS;
2628 
2629  return SCIP_OKAY;
2630 }
2631 
2632 /** returns the total number of scenarios added to the problem */
2634  SCIP* scip /**< SCIP data structure */
2635  )
2636 {
2637  SCIP_READER* reader;
2638  SCIP_READERDATA* readerdata;
2639 
2640  reader = SCIPfindReader(scip, READER_NAME);
2641 
2642  assert(reader != NULL);
2643  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
2644 
2645  readerdata = SCIPreaderGetData(reader);
2646  assert(readerdata != NULL);
2647 
2648  return readerdata->numscenarios;
2649 }
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:239
int SCIPmemccpy(char *dest, const char *src, char stop, unsigned int cnt)
Definition: misc.c:9901
#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:1937
public methods for SCIP parameter handling
static SCIP_Real computeScenarioProbability(SCIP *scip, STOSCENARIO *scenario)
Definition: reader_sto.c:1838
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:260
SCIP_Bool SCIPvarIsInitial(SCIP_VAR *var)
Definition: var.c:16930
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:393
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:2569
#define FALSE
Definition: def.h:65
static SCIP_RETCODE addScenarioVarsAndConsToProb(SCIP *scip, STOSCENARIO *scenario, SCIP_Bool decomp)
Definition: reader_sto.c:2116
#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:10017
#define TRUE
Definition: def.h:64
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:2489
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:339
SCIP_Bool SCIPvarIsRemovable(SCIP_VAR *var)
Definition: var.c:16940
#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:1980
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:1863
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:2266
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:17289
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:17309
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:16729
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:2340
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:2046
#define SCIP_CALL(x)
Definition: def.h:351
#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:4450
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:62
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:9926
STOSTOCHINFO stochinfotype
Definition: reader_sto.c:132
SCIP_CONS ** SCIPtimGetStageConss(SCIP *scip, int stagenum)
Definition: reader_tim.c:1053
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:2600
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:17191
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:1074
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:1669
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:2633
static SCIP_DECL_READERFREE(readerFreeSto)
Definition: reader_sto.c:2503
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:1879
#define SCIP_Real
Definition: def.h:150
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:2390
public methods for input file readers
#define SCIP_CALL_TERMINATE(retcode, x, TERM)
Definition: def.h:372
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:16894
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:1032
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:2316
int SCIPtimGetStageNConss(SCIP *scip, int stagenum)
Definition: reader_tim.c:1095
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:9975
SCIP_Bool SCIPvarIsDeleted(SCIP_VAR *var)
Definition: var.c:16950
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:2518
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:371
static void stoinputSyntaxerror(STOINPUT *stoi)
Definition: reader_sto.c:1186
void SCIPenableDebugSol(SCIP *scip)
Definition: scip_debug.c:132
memory allocation routines