GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
dialog_graph.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 dialog_graph.cpp
30 * @brief A dialog to write graph representations of the matrix and read partitions as decompositions.
31 * @author Martin Bergner
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36#include "gcg/dialog_graph.h"
37#include "scip/dialog_default.h"
40#include "graph/hyperrowgraph.h"
41#include "graph/hypercolgraph.h"
42#include "graph/columngraph.h"
43#include "graph/rowgraph.h"
44#include "gcg/scip_misc.h"
45#include "gcg/cons_decomp.h"
46#include "graph/graph_tclique.h"
47
48namespace gcg
49{
50
52 GCG* gcgstruct /**< GCG data structure */
53) : ObjDialog(gcgstruct, "write", "write graph to file", TRUE)
54{
55
56}
57
58SCIP_DECL_DIALOGEXEC(DialogWriteGraph::scip_exec) {
59 SCIP_CALL(SCIPdialogExecMenu(scip, dialog, dialoghdlr, nextdialog));
60 return SCIP_OKAY;
61}
62
64 GCG* gcgstruct /**< GCG data structure */
65) : ObjDialog(gcgstruct, "graph", "graph submenu to read and write graph", TRUE)
66{
67
68}
69
70SCIP_DECL_DIALOGEXEC(DialogGraph::scip_exec) {
71 SCIP_CALL(SCIPdialogExecMenu(scip, dialog, dialoghdlr, nextdialog));
72 return SCIP_OKAY;
73}
75 GCG* gcgstruct /**< GCG data structure */
76) : ObjDialog(gcgstruct, "read", "read partition from file", TRUE)
77{
78
79}
80
81SCIP_DECL_DIALOGEXEC(DialogReadPartition::scip_exec) {
82
83 SCIP_CALL(SCIPdialogExecMenu(scip, dialog, dialoghdlr, nextdialog));
84 return SCIP_OKAY;
85}
86
87template<class T, template <class T1> class G>
89 GCG* gcgstruct /**< GCG data structure */
90): ObjDialog(gcgstruct, G<T>(gcgstruct, Weights()).name.c_str(), "writes graph of given type", FALSE)
91{
92 (void)static_cast<MatrixGraph<T>*>((G<T>*)0); /* assure we only get descendants of type Graph */
93}
94
95
96template<class T,template <class T1> class G>
98{
100 {
101 *nextdialog = SCIPdialoghdlrGetRoot(dialoghdlr);
102 SCIPdialogMessage(scip, NULL, "No problem exists, read in a problem first.\n");
103 return SCIP_OKAY;
104 }
105
106 char* filename;
107 SCIP_Bool endoffile;
108
109 SCIP_CALL( SCIPdialoghdlrGetWord(dialoghdlr, dialog, "enter filename: ", &filename, &endoffile) );
110 if( endoffile )
111 {
112 *nextdialog = NULL;
113 return SCIP_OKAY;
114 }
115 if( filename[0] != '\0' )
116 {
117
118 char* extension;
119 int fd;
120 FILE* file;
121
122 extension = filename;
123
124 file = fopen(filename, "wx");
125 if( file == NULL )
127
128 fd = fileno(file);
129 if( fd == -1 )
131
132 MatrixGraph<T>* graph = new G<T>(gcg, Weights());
133 SCIP_CALL( SCIPdialoghdlrAddHistory(dialoghdlr, dialog, extension, TRUE) );
134 SCIP_CALL( graph->createFromMatrix(SCIPgetConss(scip), SCIPgetVars(scip), SCIPgetNConss(scip), SCIPgetNVars(scip)) );
135 SCIP_CALL( graph->writeToFile(fd, FALSE) );
136 delete graph;
137 SCIPdialogMessage(scip, NULL, "graph written to <%s>\n", extension);
138 }
139 *nextdialog = SCIPdialoghdlrGetRoot(dialoghdlr);
140 return SCIP_OKAY;
141}
142
143template<class T, template <class T1> class G>
145 GCG* gcgstruct /**< GCG data structure */
146): ObjDialog(gcgstruct, G<T>(gcgstruct, Weights()).name.c_str(), "reads graph of given type", FALSE)
147{
148 (void)static_cast<MatrixGraph<T>*>((G<T>*)0); /* assure we only get descendants of type Graph */
149}
150
151template<class T, template <class T1> class G>
153{
155 {
156 *nextdialog = SCIPdialoghdlrGetRoot(dialoghdlr);
157 SCIPdialogMessage(scip, NULL, "No problem exists, read in a problem first.\n");
158 return SCIP_OKAY;
159 }
160
161 char* filename;
162 SCIP_Bool endoffile;
163
164 SCIP_CALL( SCIPdialoghdlrGetWord(dialoghdlr, dialog, "enter filename: ", &filename, &endoffile) );
165 if( endoffile )
166 {
167 *nextdialog = NULL;
168 return SCIP_OKAY;
169 }
170 if( filename[0] != '\0' )
171 {
172 MatrixGraph<T>* graph = new G<T>(gcg, Weights());
173 char* extension;
174 extension = filename;
175 GCG_DECOMP* decomp;
176 SCIP_CALL( SCIPdialoghdlrAddHistory(dialoghdlr, dialog, extension, TRUE) );
177 SCIP_CALL( graph->createFromMatrix(SCIPgetConss(scip), SCIPgetVars(scip), SCIPgetNConss(scip), SCIPgetNVars(scip)) );
178 SCIP_CALL( graph->readPartition(extension) );
179 SCIP_CALL( graph->createDecompFromPartition(&decomp) );
180 delete graph;
181
183 GCGdecompFree(gcg, &decomp);
184 SCIPdialogMessage(scip, NULL, "decomposition read from <%s>\n", extension);
185 }
186 *nextdialog = SCIPdialoghdlrGetRoot(dialoghdlr);
187 return SCIP_OKAY;
188}
189
190} /* namespace gcg */
191
192/** include the graph entries for both writing the graph and reading in the partition */
193template<class T, template <class T1> class G>
195 GCG* gcg /**< GCG data structure */
196)
197{
198 SCIP_DIALOG* graphdialog;
199 SCIP_DIALOG* subdialog;
201
202 (void)static_cast<gcg::MatrixGraph<T>*>((G<T>*)0); /* assure we only get descendants of type Graph */
203
204 (void) SCIPdialogFindEntry(SCIPgetRootDialog(origprob), "graph", &graphdialog);
205 assert(graphdialog != NULL);
206
207 (void) SCIPdialogFindEntry(graphdialog, "write", &subdialog);
208 assert(subdialog != NULL);
210
211 (void) SCIPdialogFindEntry(graphdialog, "read", &subdialog);
212 assert(subdialog != NULL);
214
215 return SCIP_OKAY;
216}
217
218/** inludes all graph submenu entries */
219extern "C"
virtual SCIP_RETCODE createFromMatrix(SCIP_CONS **conss, SCIP_VAR **vars, int nconss_, int nvars_)
virtual SCIP_RETCODE readPartition(const char *filename)
virtual SCIP_RETCODE createDecompFromPartition(GCG_DECOMP **decomp)
Definition matrixgraph.h:90
virtual SCIP_RETCODE writeToFile(int fd, SCIP_Bool writeweights)
Definition matrixgraph.h:80
DialogGraph(GCG *gcg)
DialogReadGraphs(GCG *gcgstruct)
DialogWriteGraph(GCG *gcgstruct)
DialogWriteGraphs(GCG *gcgstruct)
ObjDialog(GCG *gcgstruct, const char *name, const char *desc, SCIP_Bool issubmenu)
Definition objdialog.h:74
A row graph where each column is a node and columns are adjacent if they appear in a row.
SCIP_RETCODE GCGconshdlrDecompAddPreexistingDecomp(GCG *gcg, GCG_DECOMP *decomp)
adds a decomp that exists before the detection is called
constraint handler for structure detection
SCIP_RETCODE GCGdecompFree(GCG *gcg, GCG_DECOMP **decdecomp)
Definition decomp.c:541
#define SCIP_Bool
SCIP_RETCODE GCGincludeGraphEntries(GCG *gcg)
A dialog to write graph representations of the matrix and read partitions as decompositions.
#define TRUE
#define FALSE
interface to the SCIP tclique graph library
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP_STAGE SCIPgetStage(SCIP *scip)
SCIP_CONS ** SCIPgetConss(SCIP *scip)
int SCIPgetNVars(SCIP *scip)
int SCIPgetNConss(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
SCIP_RETCODE GCGincludeDialogsGraph(GCG *gcg)
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
SCIP_DIALOG * SCIPdialoghdlrGetRoot(SCIP_DIALOGHDLR *dialoghdlr)
SCIP_RETCODE SCIPdialoghdlrAddHistory(SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog, const char *command, SCIP_Bool escapecommand)
SCIP_RETCODE SCIPdialoghdlrGetWord(SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog, const char *prompt, char **inputword, SCIP_Bool *endoffile)
SCIP_DIALOG * SCIPgetRootDialog(SCIP *scip)
int SCIPdialogFindEntry(SCIP_DIALOG *dialog, const char *entryname, SCIP_DIALOG **subdialog)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
Column hypergraph.
A hypergraph with row and column nodes.
Column hypergraph.
#define NULL
SCIP_DECL_DIALOGEXEC(DialogWriteGraph::scip_exec)
SCIP_RETCODE GCGincludeObjDialog(GCG *gcg, SCIP_DIALOG *parentdialog, gcg::ObjDialog *objdialog, SCIP_Bool deleteobject)
A row graph where each row is a node and rows are adjacent if they share a variable.
various SCIP helper methods
struct GCG_Decomp GCG_DECOMP
Definition type_decomp.h:45
struct SCIP_Dialog SCIP_DIALOG
struct SCIP_Dialoghdlr SCIP_DIALOGHDLR
struct Gcg GCG
Definition type_gcg.h:44
SCIP_FILECREATEERROR
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_PROBLEM