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