Scippy

GCG

Branch-and-Price & Column Generation for Everyone

stat.c
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 /**
29  * @file stat.c
30  * @brief Some printing methods for statistics
31  * @author Alexander Gross
32  * @author Martin Bergner
33  */
34 
35 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36 
37 #include "scip/scip.h"
38 #include "stat.h"
39 #include "scip_misc.h"
40 #include "pub_decomp.h"
41 #include "cons_decomp.h"
42 #include "struct_detector.h"
43 #include "pub_gcgvar.h"
44 #include "pricer_gcg.h"
45 #include "gcg.h"
46 #include "relax_gcg.h"
47 
48 
49 /** prints information about the best decomposition*/
51  SCIP* scip /**< SCIP data structure */
52  )
53 {
54  DEC_DECOMP* decomposition;
55 
56  DEC_DETECTOR* detector;
57  DEC_DECTYPE type;
58  const char* typeName;
59 
60  int i;
61  int nblocks;
62  int nlinkingconss;
63  int nlinkingvars;
64  int* nvarsinblocks;
65  int* nconssinblocks;
66 
67  assert(scip != NULL);
68 
69  decomposition = DECgetBestDecomp(scip, TRUE);
70  type = DECdecompGetType(decomposition);
71  typeName = DECgetStrType(type);
72 
73  detector = DECdecompGetDetector(decomposition);
74 
75  nblocks = DECdecompGetNBlocks(decomposition);
76 
77  nvarsinblocks = DECdecompGetNSubscipvars(decomposition);
78  nconssinblocks = DECdecompGetNSubscipconss(decomposition);
79 
80  nlinkingvars = DECdecompGetNLinkingvars(decomposition);
81  nlinkingconss = DECdecompGetNLinkingconss(decomposition);
82 
83  /* print information about decomposition type and number of blocks, vars, linking vars and cons */
84  SCIPinfoMessage(scip, NULL, "Decomposition:\n");
85  SCIPinfoMessage(scip, NULL, "Decomposition Type: %s \n", typeName);
86 
87  SCIPinfoMessage(scip, NULL, "Decomposition Detector: %s\n", detector == NULL ? "reader": detector->name);
88  SCIPinfoMessage(scip, NULL, "Number of Blocks: %d \n", nblocks);
89  SCIPinfoMessage(scip, NULL, "Number of LinkingVars: %d\n", nlinkingvars);
90  SCIPinfoMessage(scip, NULL, "Number of LinkingCons: %d\n", nlinkingconss);
91 
92  /* print number of variables and constraints per block */
93  SCIPinfoMessage(scip, NULL, "Block Information\n");
94  SCIPinfoMessage(scip, NULL, "no.:\t\t#Vars\t\t#Constraints\n");
95  for( i = 0; i < nblocks; i++ )
96  {
97  SCIPinfoMessage(scip, NULL, "%d:\t\t%d\t\t%d\n", i, nvarsinblocks[i], nconssinblocks[i]);
98  }
99 
100  DECdecompFree(scip, &decomposition);
101 
102  return SCIP_OKAY;
103 }
104 
105 /** prints additional solving statistics */
107  SCIP* scip /**< SCIP data structure */
108  )
109 {
110  SCIP_CLOCK* rootnodetime;
111 
112  assert(scip != NULL);
113 
114  rootnodetime = GCGgetRootNodeTime(scip);
115  SCIPinfoMessage(scip, NULL, "Solving Details :\n");
116  SCIPinfoMessage(scip, NULL, " time in root node: %10.2f\n", SCIPgetClockTime(scip, rootnodetime));
117 
118  return SCIP_OKAY;
119 }
120 
121 /** prints information about the creation of the Vars*/
123  SCIP* scip /**< SCIP data structure */
124  )
125 {
126  SCIP_VAR** vars;
127  SCIP_SOL* sol;
128  SCIP_Real solvingtime;
129  SCIP_Longint nnodes;
130 
131  int nvars, i, n;
132  SCIP_Longint* createnodestat;
133  int nodes[2]; /* Wurzel Knoten und nicht wurzelknoten */
134  SCIP_Longint createtimestat[10];
135  int createiterstat[10];
136  int m;
137 
138  assert(scip != NULL);
139 
140  vars = SCIPgetVars(scip);
141  nvars = SCIPgetNVars(scip);
142  nnodes = SCIPgetNNodes(scip);
143  sol = SCIPgetBestSol(scip);
144 
145  solvingtime = SCIPgetSolvingTime(scip);
146  assert(nnodes < INT_MAX);
147  SCIP_CALL( SCIPallocBufferArray(scip, &createnodestat, (int)nnodes) ); /* lld doesn't work here */
148 
149  SCIPinfoMessage(scip, NULL, "AddedVarDetails:\n");
150 
151  for( i = 0; i < 10; i++ )
152  {
153  createtimestat[i] = 0;
154  createiterstat[i] = 0;
155  }
156 
157  nodes[0] = 0;
158  nodes[1] = 0;
159 
160  SCIPinfoMessage(scip, NULL, "VAR: name\tnode\ttime\titer\trootredcostcall\tredcost\tgap\tsolval\trootlpsolval\n");
161  for( i = 0; i < nvars; i++ )
162  {
163  SCIP_Real redcost;
164  SCIP_Real gap;
165  SCIP_Longint node;
166  SCIP_Real time;
167  SCIP_Longint iteration;
168  SCIP_Longint rootredcostcall;
169  SCIP_Real rootlpsolval;
170 
171  node = GCGgetCreationNode(vars[i]);
172  time = GCGgetCreationTime(vars[i]);
173  iteration = GCGgetIteration(vars[i]);
174  redcost = GCGgetRedcost(vars[i]);
175  gap = GCGgetVarGap(vars[i]);
176  rootredcostcall = GCGgetRootRedcostCall(vars[i]);
177 
178  rootlpsolval = NAN;
179 
180 #ifdef SCIP_STATISTIC
181  rootlpsolval = SCIPgetSolVal(scip, GCGmasterGetRootLPSol(scip), vars[i]);
182 #endif
183  SCIPinfoMessage(scip, NULL, "VAR: <%s>\t%lld\t%f\t%lld\t%lld\t%f\t%f\t%f\t%f\n", SCIPvarGetName(vars[i]), node, time,
184  iteration, rootredcostcall, redcost, gap, SCIPgetSolVal(scip, sol, vars[i]), rootlpsolval);
185 
186  if( SCIPisEQ(scip, SCIPgetSolVal(scip, sol, vars[i]), 0.0) )
187  {
188  continue;
189  }
190  else
191  {
192  SCIPdebugMessage("var <%s> has sol value %f (%lld, %f)\n", SCIPvarGetName(vars[i]),
193  SCIPgetSolVal(scip, sol, vars[i]), node, time);
194  }
195 
196  n = (int)(100 * time / solvingtime) % 10;
197  m = (int)(100 * iteration / SCIPgetNLPIterations(scip)) % 10;
198  createiterstat[n]++;
199  createtimestat[m]++;
200 
201  if( node == 1 )
202  {
203  nodes[0]++;
204  }
205  else
206  {
207  nodes[1]++;
208  }
209  }
210 
211  SCIPinfoMessage(scip, NULL, "Root node:\tAdded Vars %d\n", nodes[0]);
212  SCIPinfoMessage(scip, NULL, "Leftover nodes:\tAdded Vars %d\n", nodes[1]);
213 
214  for( i = 0; i < 10; i++ )
215  {
216  SCIPinfoMessage(scip, NULL, "Time %d-%d%%: Vars: %lld \n", 10 * i, 10 * (i + 1), createtimestat[i]);
217  }
218 
219  for( i = 0; i < 10; i++ )
220  {
221  SCIPinfoMessage(scip, NULL, "Iter %d-%d%%: Vars: %d \n", 10 * i, 10 * (i + 1), createiterstat[i]);
222  }
223 
224  SCIPfreeBufferArray(scip, &createnodestat);
225 
226  return SCIP_OKAY;
227 }
DEC_DECTYPE DECdecompGetType(DEC_DECOMP *decomp)
Definition: decomp.c:691
GCG interface methods.
SCIP_CLOCK * GCGgetRootNodeTime(SCIP *scip)
Definition: relax_gcg.c:5181
int DECdecompGetNLinkingconss(DEC_DECOMP *decomp)
Definition: decomp.c:977
constraint handler for structure detection
int * DECdecompGetNSubscipconss(DEC_DECOMP *decomp)
Definition: decomp.c:917
DEC_DETECTOR * DECdecompGetDetector(DEC_DECOMP *decomp)
Definition: decomp.c:1590
data structures for detectors
GCG variable pricer.
various SCIP helper methods
const char * DECgetStrType(DEC_DECTYPE type)
Definition: decomp.c:462
SCIP_RETCODE GCGwriteDecompositionData(SCIP *scip)
Definition: stat.c:50
long long int GCGgetCreationNode(SCIP_VAR *var)
Definition: gcgvar.c:1606
int * DECdecompGetNSubscipvars(DEC_DECOMP *decomp)
Definition: decomp.c:833
SCIP_RETCODE DECdecompFree(SCIP *scip, DEC_DECOMP **decdecomp)
Definition: decomp.c:530
SCIP_RETCODE GCGwriteVarCreationDetails(SCIP *scip)
Definition: stat.c:122
int DECdecompGetNLinkingvars(DEC_DECOMP *decomp)
Definition: decomp.c:1046
SCIP_Longint GCGgetRootRedcostCall(SCIP_VAR *var)
Definition: gcgvar.c:1662
SCIP_Real GCGgetVarGap(SCIP_VAR *var)
Definition: gcgvar.c:1718
SCIP_Longint GCGgetIteration(SCIP_VAR *var)
Definition: gcgvar.c:1690
GCG relaxator.
Prints information about the best decomposition.
enum Dectype DEC_DECTYPE
Definition: type_decomp.h:56
SCIP_Real GCGgetRedcost(SCIP_VAR *var)
Definition: gcgvar.c:1748
int DECdecompGetNBlocks(DEC_DECOMP *decomp)
Definition: decomp.c:745
const char * name
public methods for GCG variables
SCIP_Real GCGgetCreationTime(SCIP_VAR *var)
Definition: gcgvar.c:1634
SCIP_RETCODE GCGwriteSolvingDetails(SCIP *scip)
Definition: stat.c:106
DEC_DECOMP * DECgetBestDecomp(SCIP *scip, SCIP_Bool printwarnings)
Gets the best known decomposition.
public methods for working with decomposition structures