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 and library */
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-2026 Operations Research, RWTH Aachen University */
10/* Zuse Institute Berlin (ZIB) */
11/* */
12/* Licensed under the Apache License, Version 2.0 (the "License"); */
13/* you may not use this file except in compliance with the License. */
14/* You may obtain a copy of the License at */
15/* */
16/* http://www.apache.org/licenses/LICENSE-2.0 */
17/* */
18/* Unless required by applicable law or agreed to in writing, software */
19/* distributed under the License is distributed on an "AS IS" BASIS, */
20/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
21/* See the License for the specific language governing permissions and */
22/* limitations under the License. */
23/* */
24/* You should have received a copy of the Apache-2.0 license */
25/* along with GCG; see the file LICENSE. If not visit gcg.or.rwth-aachen.de.*/
26/* */
27/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28
29/**@file miscvisualization.cpp
30 * @brief miscellaneous methods for visualizations
31 * @author Hanna Franzen
32 *
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
37
38#include "gcg/cons_decomp.h"
42
43#include "scip/scip.h"
44
45#if defined(_WIN32) || defined(_WIN64)
46#include <windows.h>
47#else
48#include <unistd.h>
49#endif
50
51#include <stdlib.h>
52#include <sstream>
53
54using namespace gcg;
55
56
57/* Gives a consistent filename for a (single) partialdec visualization that includes the probname and partialdecID
58 *
59 * @returns standardized filename
60 */
62 GCG* gcg, /* scip data structure */
63 PARTIALDECOMP* partialdec, /* partialdec that is to be visualized */
64 const char* extension, /* file extension (to be included in the name) */
65 char* filename /* filename output */
66 )
67{
68 SCIP* scip;
69 char* name;
70 char detectorchainstring[SCIP_MAXSTRLEN];
71 char probname[SCIP_MAXSTRLEN];
72
74 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN, "%s", SCIPgetProbName(scip));
75 SCIPsplitFilename(probname, NULL, &name, NULL, NULL);
76
77 /* get detector chain string*/
78 partialdec->buildDecChainString(detectorchainstring);
79
80 assert( partialdec != NULL );
81
82 /* print header */
83 if(strlen(detectorchainstring) > 0)
84 {
85 /* if there is a PARTIALDECOMP that was detected in GCG */
86 (void) SCIPsnprintf(filename, SCIP_MAXSTRLEN, "%s-%s-%d-%d%s", name, detectorchainstring, partialdec->getID(),
87 partialdec->getNBlocks(), extension);
88 }
89 else
90 {
91 /* if there is a PARTIALDECOMP but it was not detected in GCG */
92 (void) SCIPsnprintf(filename, SCIP_MAXSTRLEN, "%s-%d-%d%s", name, partialdec->getID(),
93 partialdec->getNBlocks(), extension);
94 }
95
96 /* some filenames can still have dots in them (usually from prob name) which can cause confusion.
97 * Does not replace characters in the file extension. */
98 for(size_t i = 0; i < strlen(filename) - strlen(extension); i++)
99 {
100 if(filename[i] == '.')
101 filename[i] = '-';
102
103 if(filename[i] == '(')
104 filename[i] = '-';
105
106 if(filename[i] == ')')
107 filename[i] = '-';
108 }
109}
110
111
112/* Gives the path of the provided file */
114 FILE* file, /* file */
115 char* path /* buffer containing the path afterward, must be of length PATH_MAX! */
116 )
117{
118 char sympath[SCIP_MAXSTRLEN];
119 int filedesc;
120
121 filedesc = fileno(file); /* get link to file descriptor */
122 if( filedesc < 0 )
123 {
124 SCIPerrorMessage("File reading error, no fileno!\n");
125 return;
126 }
127 SCIPsnprintf(sympath, SCIP_MAXSTRLEN, "/proc/self/fd/%d", filedesc); /* set symbolic link to file */
128 realpath(sympath, path);
129}
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
class to manage partial decompositions
GCG_EXPORT void buildDecChainString(char *buffer)
creates a detector chain short string for this partialdec, is built from detector chain
GCG_EXPORT int getID()
returns the unique id of the partialdec
GCG_EXPORT int getNBlocks()
Gets the number of blocks.
constraint handler for structure detection
#define SCIP_MAXSTRLEN
void SCIPsplitFilename(char *filename, char **path, char **name, char **extension, char **compression)
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
const char * SCIPgetProbName(SCIP *scip)
int SCIPsnprintf(char *t, int len, const char *s,...)
#define NULL
void GCGgetFilePath(FILE *file, char *path)
void GCGgetVisualizationFilename(GCG *gcg, PARTIALDECOMP *partialdec, const char *extension, char *filename)
miscellaneous methods for visualizations
#define SCIPerrorMessage
Definition: struct_gcg.h:55