class_miscvisualization.cpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program */
4 /* GCG --- Generic Column Generation */
5 /* a Dantzig-Wolfe decomposition based extension */
6 /* of the branch-cut-and-price framework */
7 /* SCIP --- Solving Constraint Integer Programs */
8 /* */
9 /* Copyright (C) 2010-2018 Operations Research, RWTH Aachen University */
10 /* Zuse Institute Berlin (ZIB) */
11 /* */
12 /* This program is free software; you can redistribute it and/or */
13 /* modify it under the terms of the GNU Lesser General Public License */
14 /* as published by the Free Software Foundation; either version 3 */
15 /* of the License, or (at your option) any later version. */
16 /* */
17 /* This program is distributed in the hope that it will be useful, */
18 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
19 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
20 /* GNU Lesser General Public License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with this program; if not, write to the Free Software */
24 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.*/
25 /* */
26 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include "cons_decomp.h"
38 #include "class_seeedpool.h"
39 #include "class_seeed.h"
40 #include "wrapper_seeed.h"
41 
42 #include "scip/scip.h"
43 
44 #include <unistd.h>
45 #include <stdlib.h>
46 #include <sstream>
47 
48 using namespace gcg;
49 
50 
53 
56 
62  SCIP* scip,
63  SeeedPtr seeed,
64  const char* extension,
65  char* filename
66  )
67 {
68  char* name;
69  char* detectorchainstring;
70  char probname[SCIP_MAXSTRLEN];
71 
72  (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN, "%s", SCIPgetProbName(scip));
73  SCIPsplitFilename(probname, NULL, &name, NULL, NULL);
74 
75  /* get detector chain string*/
76  detectorchainstring = seeed->getDetectorChainString();
77 
78  /* print header */
79  if( seeed == NULL )
80  /* if there is no Seeed, print the problem name only */
81  (void) SCIPsnprintf(filename, SCIP_MAXSTRLEN, "%s", name);
82  else if(detectorchainstring != NULL)
83  {
84  /* if there is a Seeed that was detected in GCG */
85  (void) SCIPsnprintf(filename, SCIP_MAXSTRLEN, "%s-%s-%d-%d-%s", name, detectorchainstring, seeed->getID(),
86  seeed->getNBlocks(), extension);
87  }
88  else
89  {
90  /* if there is a Seeed but it was not detected in GCG */
91  (void) SCIPsnprintf(filename, SCIP_MAXSTRLEN, "%s-%d-%d-%s", name, seeed->getID(),
92  seeed->getNBlocks(), extension);
93  }
94 
95  /* some filenames can still have dots in them (usually from prob name) which can cause confusion */
96  for(size_t i = 0; i < strlen(filename); i++)
97  {
98  if(filename[i] == '.')
99  filename[i] = '-';
100  }
101 
102  return SCIP_OKAY;
103 }
104 
105 
108  SCIP* scip,
109  FILE* file
110  )
111 {
112  char* pfile = {};
113  char sympath[SCIP_MAXSTRLEN];
114  int filedesc;
115 
116  filedesc = fileno(file); /* get link to file descriptor */
117  if( filedesc < 0 )
118  {
119  SCIPerrorMessage("File reading error, no fileno!\n");
120  }
121  snprintf(sympath, SCIP_MAXSTRLEN, "/proc/self/fd/%d", filedesc); /* set symbolic link to file */
122  pfile = realpath(sympath, NULL);
123 
124  return pfile;
125 }
126 
127 
133  SCIP* scip,
134  int seeedid
135  )
136 {
137  SEEED_WRAPPER seeedwr;
138  Seeedpool* seeedpool;
139 
140  GCGgetCurrentSeeedpools(scip, &seeedwr, NULL);
141  seeedpool = seeedwr.seeedpool;
142 
143  /* find in presolved */
144 
145  if( seeedpool != NULL )
146  {
147  for( int i = 0; i < seeedpool->getNAncestorSeeeds(); ++i)
148  {
149  if( seeedpool->getAncestorSeeed(i)!= NULL && seeedpool->getAncestorSeeed(i)->getID() == seeedid )
150  return seeedpool;
151  }
152 
153  for( int i = 0; i < seeedpool->getNIncompleteSeeeds(); ++i)
154  {
155  if( seeedpool->getIncompleteSeeed(i)->getID() == seeedid )
156  return seeedpool;
157  }
158 
159  for( int i = 0; i < seeedpool->getNFinishedSeeeds(); ++i)
160  {
161  if( seeedpool->getFinishedSeeed(i)->getID() == seeedid )
162  return seeedpool;
163  }
164 
165  for( int i = 0; i < seeedpool->getNCurrentSeeeds(); ++i)
166  {
167  if( seeedpool->getCurrentSeeed(i)->getID() == seeedid )
168  return seeedpool;
169  }
170  }
171 
172  /* find in unpresolved */
173  GCGgetCurrentSeeedpools(scip, NULL, &seeedwr);
174  seeedpool = seeedwr.seeedpool;
175 
176  if( seeedpool != NULL )
177  {
178  for( int i = 0; i < seeedpool->getNAncestorSeeeds(); ++i)
179  {
180  if( seeedpool->getAncestorSeeed(i)!= NULL && seeedpool->getAncestorSeeed(i)->getID() == seeedid )
181  return seeedpool;
182  }
183 
184  for( int i = 0; i < seeedpool->getNIncompleteSeeeds(); ++i)
185  {
186  if( seeedpool->getIncompleteSeeed(i)->getID() == seeedid )
187  return seeedpool;
188  }
189 
190  for( int i = 0; i < seeedpool->getNFinishedSeeeds(); ++i)
191  {
192  if( seeedpool->getFinishedSeeed(i)->getID() == seeedid )
193  return seeedpool;
194  }
195 
196  for( int i = 0; i < seeedpool->getNCurrentSeeeds(); ++i)
197  {
198  if( seeedpool->getCurrentSeeed(i)->getID() == seeedid )
199  return seeedpool;
200  }
201  }
202 
203  return NULL;
204 }
SeeedPtr getFinishedSeeed(int seeedindex)
returns a seeed from finished seeed data structure
SCIP_RETCODE GCGgetCurrentSeeedpools(SCIP *scip, SEEED_WRAPPER *seeedpoolwr, SEEED_WRAPPER *seeedpoolunpresolvedwr)
SeeedPtr getCurrentSeeed(int seeedindex)
SeeedPtr getAncestorSeeed(int seeedindex)
returns a seeed from ancestor seeed data structure with given index
miscellaneous methods for visualizations
Seeedpool * GCGgetSeeedpoolForSeeed(SCIP *scip, int seeedid)
int getNAncestorSeeeds()
returns size of ancestor seeed data structure
SCIP_RETCODE GCGgetVisualizationFilename(SCIP *scip, SeeedPtr seeed, const char *extension, char *filename)
class to manage partial decompositions (aka seeed), each seeed corresponds to one seeedpool which con...
Definition: class_seeed.h:71
char * GCGgetFilePath(SCIP *scip, FILE *file)
int getID()
returns the unique id of the seeed
int getNBlocks()
returns the number of blocks
SeeedPtr getIncompleteSeeed(int seeedindex)
returns a seeed from incomplete seeed data structure
Provides wrapping to have Seeeds and Seeedpools as parameters in C-conform function headers with C++ ...
gcg::Seeedpool * seeedpool
Definition: wrapper_seeed.h:46
char * getDetectorChainString()
the detectorchainstring contains the chars of all detectors that worked on this seeed in this order ...
int getNCurrentSeeeds()
returns size of current (open) seeed data structure
class with functions for seeed pool where a seeed is a (potentially incomplete) description of a deco...
constraint handler for structure detection