Scippy

GCG

Branch-and-Price & Column Generation for Everyone

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-2021 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 
28 /**@file miscvisualization.cpp
29  * @brief miscellaneous methods for visualizations
30  * @author Hanna Franzen
31  *
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include "cons_decomp.h"
37 #include "miscvisualization.h"
38 #include "class_detprobdata.h"
39 #include "class_partialdecomp.h"
40 
41 #include "scip/scip.h"
42 
43 #include <unistd.h>
44 #include <stdlib.h>
45 #include <sstream>
46 
47 using namespace gcg;
48 
49 
50 /* Gives a consistent filename for a (single) partialdec visualization that includes the probname and partialdecID
51  *
52  * @returns standardized filename
53  */
55  SCIP* scip, /* scip data structure */
56  PARTIALDECOMP* partialdec, /* partialdec that is to be visualized */
57  const char* extension, /* file extension (to be included in the name) */
58  char* filename /* filename output */
59  )
60 {
61  char* name;
62  char detectorchainstring[SCIP_MAXSTRLEN];
63  char probname[SCIP_MAXSTRLEN];
64 
65  (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN, "%s", SCIPgetProbName(scip));
66  SCIPsplitFilename(probname, NULL, &name, NULL, NULL);
67 
68  /* get detector chain string*/
69  partialdec->buildDecChainString(detectorchainstring);
70 
71  assert( partialdec != NULL );
72 
73  /* print header */
74  if(strlen(detectorchainstring) > 0)
75  {
76  /* if there is a PARTIALDECOMP that was detected in GCG */
77  (void) SCIPsnprintf(filename, SCIP_MAXSTRLEN, "%s-%s-%d-%d%s", name, detectorchainstring, partialdec->getID(),
78  partialdec->getNBlocks(), extension);
79  }
80  else
81  {
82  /* if there is a PARTIALDECOMP but it was not detected in GCG */
83  (void) SCIPsnprintf(filename, SCIP_MAXSTRLEN, "%s-%d-%d%s", name, partialdec->getID(),
84  partialdec->getNBlocks(), extension);
85  }
86 
87  /* some filenames can still have dots in them (usually from prob name) which can cause confusion.
88  * Does not replace characters in the file extension. */
89  for(size_t i = 0; i < strlen(filename) - strlen(extension); i++)
90  {
91  if(filename[i] == '.')
92  filename[i] = '-';
93 
94  if(filename[i] == '(')
95  filename[i] = '-';
96 
97  if(filename[i] == ')')
98  filename[i] = '-';
99  }
100 }
101 
102 
103 /* Gives the path of the provided file */
105  FILE* file, /* file */
106  char* path /* buffer containing the path afterward, must be of length PATH_MAX! */
107  )
108 {
109  char sympath[SCIP_MAXSTRLEN];
110  int filedesc;
111 
112  filedesc = fileno(file); /* get link to file descriptor */
113  if( filedesc < 0 )
114  {
115  SCIPerrorMessage("File reading error, no fileno!\n");
116  return;
117  }
118  SCIPsnprintf(sympath, SCIP_MAXSTRLEN, "/proc/self/fd/%d", filedesc); /* set symbolic link to file */
119  realpath(sympath, path);
120 }
constraint handler for structure detection
void buildDecChainString(char *buffer)
creates a detector chain short string for this partialdec, is built from detector chain
miscellaneous methods for visualizations
class to manage partial decompositions
int getNBlocks()
Gets the number of blocks.
void GCGgetFilePath(FILE *file, char *path)
int getID()
returns the unique id of the partialdec
class storing (potentially incomplete) decompositions
class storing partialdecs and the problem matrix
void GCGgetVisualizationFilename(SCIP *scip, PARTIALDECOMP *partialdec, const char *extension, char *filename)