Scippy

SCIP

Solving Constraint Integer Programs

reader_stp.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-2015 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 email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file reader_stp.c
17  * @brief Steiner tree problem file reader
18  * @author Gerald Gamrath
19  * @author Thorsten Koch
20  * @author Daniel Rehfeldt
21  * @author Michael Winkler
22  *
23  * This file implements the reader used to read and write Steiner tree problems.
24  */
25 
26 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
27 
28 #include <assert.h>
29 #include <string.h>
30 
31 #include "probdata_stp.h"
32 #include "reader_stp.h"
33 #include "grph.h"
34 
35 
36 /**@name Reader properties
37  *
38  * @{
39  */
40 
41 #define READER_NAME "stpreader"
42 #define READER_DESC "file reader for steiner tree data format"
43 #define READER_EXTENSION "stp"
44 
45 #define DEFAULT_COMPCENTRAL 1 /**< selection type for the root (for undirected STPs) */
46 #define DEFAULT_EMITGRAPH FALSE /**< emit graph? */
47 #define DEFAULT_COUNTPRESOLTIME TRUE /**< count presolving time as part of overall solution time? */
48 #define DEFAULT_REDUCTION 2 /**< reduction mode to apply */
49 #define DEFAULT_SYMCONS 2 /**< symmetry constraints */
50 #define DEFAULT_CYCLECONS 2 /**< cycle constraints */
51 #define DEFAULT_MINELIMS 3 /**< minimal number of eliminations to be achieved for reiteration of reduction methods */
52 #define DEFAULT_PRETIMELIMIT -1.0 /**< presolving time limit */
53 
54 #define STP_MODES "cfp" /**< valid values for user parameter 'stp/mode' */
55 
56 /**@} */
57 
58 
59 /**@name Callback methods
60  *
61  * @{
62  */
63 
64 /** copy method for reader plugins (called when SCIP copies plugins) */
65 static
66 SCIP_DECL_READERCOPY(readerCopyStp)
67 { /*lint --e{715}*/
68  assert(scip != NULL);
69  assert(reader != NULL);
70  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
71 
72  /* call inclusion method of reader */
73  SCIP_CALL( SCIPincludeReaderStp(scip) );
74 
75  return SCIP_OKAY;
76 }
77 
78 /** problem reading method of the reader */
79 static
80 SCIP_DECL_READERREAD(readerReadStp)
81 { /*lint --e{715}*/
82  SCIP_RETCODE retcode;
83  SCIP_PROBDATA* probdata;
84  char mode;
85 
86  *result = SCIP_DIDNOTRUN;
87 
88  /* get solving mode parameter */
89  SCIP_CALL( SCIPgetCharParam(scip, "stp/mode", &mode) );
90 
91  retcode = SCIPprobdataCreate(scip, filename);
92 
93  if( retcode == SCIP_READERROR )
94  return SCIP_READERROR;
95 
96  SCIP_CALL( retcode );
97 
98  probdata = SCIPgetProbData(scip);
99  if( SCIPgetStage(scip) == SCIP_STAGE_INIT || probdata == NULL )
100  return SCIP_READERROR;
101  else if(SCIPprobdataGetGraph(probdata) != NULL && mode == 'p')
102  {
103  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL, "activate pricer\n");
104 #if 0
105  SCIP_CALL( SCIPsetBoolParam(scip, "propagating/pseudoobj/force", TRUE) );
106 #endif
107  SCIP_CALL( SCIPactivatePricer(scip, SCIPfindPricer(scip, "stp")) );
108  }
109 
110  *result = SCIP_SUCCESS;
111  return SCIP_OKAY;
112 }
113 
114 /** problem writing method of the reader */
115 static
116 SCIP_DECL_READERWRITE(readerWriteStp)
117 { /*lint --e{715}*/
118  const GRAPH* graph;
119  SCIP_Real offset;
120 
121  /* get the graph of the problem */
122  graph = SCIPprobdataGetGraph(probdata);
123 
124  /* get the offset of the problem */
125  offset = SCIPprobdataGetOffset(scip);
126 
127  /* save the graph in a .stp file */
128  SCIPwriteStp(scip, graph, file, offset);
129 
130  *result = SCIP_SUCCESS;
131  return SCIP_OKAY;
132 }
133 
134 /**@} */
135 
136 
137 /**@name Interface methods
138  *
139  * @{
140  */
141 
142 /** includes the stp file reader in SCIP */
143 SCIP_RETCODE SCIPincludeReaderStp(
144  SCIP* scip /**< SCIP data structure */
145  )
146 {
147  SCIP_READERDATA* readerdata;
148  SCIP_READER* reader;
149 
150  /* create reader data */
151  readerdata = NULL;
152 
153  /* include reader */
154  SCIP_CALL( SCIPincludeReaderBasic(scip, &reader, READER_NAME, READER_DESC, READER_EXTENSION, readerdata) );
155  assert(reader != NULL);
156 
157  SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopyStp) );
158  SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadStp) );
159  SCIP_CALL( SCIPsetReaderWrite(scip, reader, readerWriteStp) );
160 
161  /* include user parameters */
162  SCIP_CALL( SCIPaddIntParam(scip,
163  "stp/compcentral",
164  "Comp. Central Term: 0 disable, 1 max. degree, 2 min. dist. sum to all terminals, 3 min. max. dist., 4 min. dist to all nodes",
165  NULL, FALSE, DEFAULT_COMPCENTRAL, 0, 4, NULL, NULL) );
166 
167  SCIP_CALL( SCIPaddIntParam(scip,
168  "stp/reduction",
169  "Reduction: 0 disable, 1 diminish, 2 default",
170  NULL, FALSE, DEFAULT_REDUCTION, 0, 2, NULL, NULL) );
171 
172  SCIP_CALL( SCIPaddIntParam(scip,
173  "stp/usesymcons",
174  "Use symmetry constraints (PC, MW): 0 never, 1 always, 2 problem specific",
175  NULL, FALSE, DEFAULT_SYMCONS, 0, 2, NULL, NULL) );
176 
177  SCIP_CALL( SCIPaddIntParam(scip,
178  "stp/usecyclecons",
179  "Use 2-cycle constraints (PC): 0 never, 1 always, 2 problem specific",
180  NULL, FALSE, DEFAULT_CYCLECONS, 0, 2, NULL, NULL) );
181 
182  SCIP_CALL( SCIPaddIntParam(scip,
183  "stp/minelims",
184  "minimal number of eliminations per reduction method",
185  NULL, FALSE, DEFAULT_MINELIMS, 0, 10000, NULL, NULL) );
186 
187  SCIP_CALL( SCIPaddRealParam(scip,
188  "stp/pretimelimit",
189  "presolving time limit",
190  NULL, FALSE, DEFAULT_PRETIMELIMIT, -1.0, SCIPinfinity(scip), NULL, NULL) );
191 
192  SCIP_CALL( SCIPaddBoolParam(scip,
193  "stp/countpresoltime",
194  "count presolving time to solving time?",
195  NULL, FALSE, DEFAULT_COUNTPRESOLTIME, NULL, NULL) );
196 
197  SCIP_CALL( SCIPaddBoolParam(scip,
198  "stp/emitgraph",
199  "Emit graph",
200  NULL, FALSE, DEFAULT_EMITGRAPH, NULL, NULL) );
201 
202  SCIP_CALL( SCIPaddBoolParam(scip,
203  "stp/bigt",
204  "use 'T' model", NULL, FALSE, FALSE, NULL, NULL) );
205 
206  SCIP_CALL( SCIPaddBoolParam(scip,
207  "stp/printGraph",
208  "print the graph before and after the presolving", NULL, FALSE, FALSE, NULL, NULL) );
209 
210  SCIP_CALL( SCIPaddCharParam(scip,
211  "stp/mode",
212  "Solving mode: 'c'ut, 'f'low ,'p'rice",
213  NULL, FALSE, 'c', STP_MODES, NULL, NULL) );
214 
215  SCIP_CALL( SCIPaddStringParam(scip,
216  "stp/logfile",
217  "log file in DIMACS challenge format",
218  NULL, FALSE, "",
219  NULL, NULL) );
220 
221  SCIP_CALL( SCIPaddStringParam(scip,
222  "stp/intlogfile",
223  "log file in DIMACS challenge format for intermediate solutions",
224  NULL, FALSE, "",
225  NULL, NULL) );
226 
227 
228 
229  return SCIP_OKAY;
230 }
231 
232 /**@} */
#define READER_EXTENSION
Definition: reader_stp.c:43
void SCIPwriteStp(SCIP *, const GRAPH *, FILE *, SCIP_Real)
Definition: grphsave.c:38
#define DEFAULT_CYCLECONS
Definition: reader_stp.c:50
#define DEFAULT_COMPCENTRAL
Definition: reader_stp.c:45
Definition: grph.h:55
#define TRUE
Definition: portab.h:34
#define DEFAULT_REDUCTION
Definition: reader_stp.c:48
#define READER_DESC
Definition: reader_stp.c:42
#define DEFAULT_EMITGRAPH
Definition: reader_stp.c:46
Problem data for stp problem.
Steiner tree problem file reader.
GRAPH * SCIPprobdataGetGraph(SCIP_PROBDATA *probdata)
#define DEFAULT_MINELIMS
Definition: reader_stp.c:51
#define FALSE
Definition: portab.h:37
#define READER_NAME
Definition: reader_stp.c:41
static SCIP_DECL_READERWRITE(readerWriteStp)
Definition: reader_stp.c:116
SCIP_Real SCIPprobdataGetOffset(SCIP *scip)
SCIP_RETCODE SCIPincludeReaderStp(SCIP *scip)
Definition: reader_stp.c:143
static SCIP_DECL_READERCOPY(readerCopyStp)
Definition: reader_stp.c:66
SCIP_RETCODE SCIPprobdataCreate(SCIP *scip, const char *filename)
#define STP_MODES
Definition: reader_stp.c:54
#define DEFAULT_SYMCONS
Definition: reader_stp.c:49
static SCIP_DECL_READERREAD(readerReadStp)
Definition: reader_stp.c:80
includes various files containing graph methods used for Steiner problems
#define DEFAULT_PRETIMELIMIT
Definition: reader_stp.c:52
#define DEFAULT_COUNTPRESOLTIME
Definition: reader_stp.c:47