SCIP-SDP  2.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
branch_sdpmostinf.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of SCIPSDP - a solving framework for mixed-integer */
4 /* semidefinite programms based on SCIP. */
5 /* */
6 /* Copyright (C) 2011-2013 Discrete Optimization, TU Darmstadt */
7 /* EDOM, FAU Erlangen-Nürnberg */
8 /* 2014-2016 Discrete Optimization, TU Darmstadt */
9 /* */
10 /* */
11 /* This program is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public License */
13 /* as published by the Free Software Foundation; either version 3 */
14 /* of the License, or (at your option) any later version. */
15 /* */
16 /* This program is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19 /* GNU Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with this program; if not, write to the Free Software */
23 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.*/
24 /* */
25 /* */
26 /* Based on SCIP - Solving Constraint Integer Programs */
27 /* Copyright (C) 2002-2016 Zuse Institute Berlin */
28 /* SCIP is distributed under the terms of the SCIP Academic Licence, */
29 /* see file COPYING in the SCIP distribution. */
30 /* */
31 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
32 
40 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
41 
42 /*#define SCIP_DEBUG*/
43 
44 #include <assert.h>
45 #include <string.h>
46 
47 #include "branch_sdpmostinf.h"
48 
49 /* turn off lint warnings for whole file: */
50 /*lint --e{788,818}*/
51 
52 #define BRANCHRULE_NAME "sdpmostinf"
53 #define BRANCHRULE_DESC "branch on the most infeasible variable of the SDP"
54 #define BRANCHRULE_PRIORITY 1000000
55 #define BRANCHRULE_MAXDEPTH -1
56 #define BRANCHRULE_MAXBOUNDDIST 1.0
57 
58 
59 /*
60  * Data structures
61  */
62 
63 /*
64  * Local methods
65  */
66 
67 /* put your local methods here, and declare them static */
68 
69 
70 /*
71  * Callback methods of branching rule
72  */
73 
75 static
76 SCIP_DECL_BRANCHCOPY(branchCopySdpmostinf)
77 { /*lint --e{715}*/
78  assert(scip != NULL);
79  assert(branchrule != NULL);
80  assert(strcmp(SCIPbranchruleGetName(branchrule), BRANCHRULE_NAME) == 0);
81 
82  /* call inclusion method of branchrule */
83  SCIP_CALL( SCIPincludeBranchruleSdpmostinf(scip) );
84 
85  return SCIP_OKAY;
86 }
87 
89 static
90 SCIP_DECL_BRANCHEXECEXT(branchExecextSdpmostinf)
91 {/*lint --e{715}*/
92  int i;
93  int ncands;
94  SCIP_VAR** cands = NULL;
95  SCIP_Real* candssol; /* solution values of all candidates */
96  SCIP_Real* candsscore; /* scores of all candidates */
97  SCIP_Real currentfrac; /* fractionality of the current candidate */
98  SCIP_Real currentinf; /* infeasibility of the current candidate */
99  SCIP_Real mostinfinf; /* infeasibility of the current most infeasible variable */
100  SCIP_Real mostinfscore; /* score of the current most infeasible variable */
101  SCIP_Real mostinfobj; /* objective of the current most infeasible variable */
102  SCIP_Real mostinfval; /* value of the current most infeasible variable */
103  SCIP_VAR* mostinfvar = NULL; /* variable with the highest current infeasibility */
104 
105 
106  assert( scip != NULL );
107  assert( result != NULL );
108 
109  SCIPdebugMessage("Executing External Branching method of SDP-mostinf!\n");
110 
111  /* get the external candidates, as we use the score only as a tiebreaker, we aren't interested in the number of
112  * variables of different types with maximal score, so these return values are set to NULL */
113  SCIP_CALL( SCIPgetExternBranchCands(scip, &cands, &candssol, &candsscore, &ncands, NULL, NULL, NULL, NULL) );
114 
115  assert( ncands > 0 ); /* branchExecext should only be called if the list of extern branching candidate is non-empty */
116 
117 #ifdef SCIP_DEBUG
118  SCIPdebugMessage("branching candidates for SDP-mostinf:\n");
119  for (i = 0; i < ncands; i++)
120  SCIPdebugMessage("%s, value = %f, score = %f\n", SCIPvarGetName(cands[i]), candssol[i], candsscore[i]);
121 #endif
122 
123  mostinfinf = -1.0;
124  mostinfscore = 0.0;
125  mostinfval = 0.0;
126  mostinfobj = -1.0;
127 
128  /* iterate over all solution candidates to find the one with the highest infeasibility */
129  for (i = 0; i < ncands; i++)
130  {
131  currentfrac = SCIPfeasFrac(scip, candssol[i]);
132  currentinf = (currentfrac <= 0.5) ? currentfrac : 1 - currentfrac;
133  /* a candidate is better than the current one if:
134  * - the infeasibility is (feastol-)bigger than before or
135  * - the infeasibility is (feastol-)equal and the score is (epsilon-)bigger or
136  * - the infeasibility and score are (feastol-/epsilon-)equal and the objective is (epsilon-)bigger than before
137  * - add three above are (feastol-/epsilon-)equal and the index is smaller */
138  if ( SCIPisFeasGT(scip, currentinf, mostinfinf) ||
139  (SCIPisFeasEQ(scip, currentinf, mostinfinf) && SCIPisGT(scip, candsscore[i], mostinfscore)) ||
140  (SCIPisFeasEQ(scip, currentinf, mostinfinf) && SCIPisEQ(scip, candsscore[i], mostinfscore) && SCIPisGT(scip, SCIPvarGetObj(cands[i]), mostinfobj)) ||
141  (SCIPisFeasEQ(scip, currentinf, mostinfinf) && SCIPisEQ(scip, candsscore[i], mostinfscore) && SCIPisEQ(scip, SCIPvarGetObj(cands[i]), mostinfobj) &&
142  SCIPvarGetIndex(cands[i]) < SCIPvarGetIndex(mostinfvar)) )
143  {
144  /* update the current best candidate */
145  mostinfinf = currentinf;
146  mostinfval = candssol[i];
147  mostinfobj = REALABS(SCIPvarGetObj(cands[i]));
148  mostinfscore = candsscore[i];
149  mostinfvar = cands[i];
150  }
151  }
152 
153  assert( mostinfvar != NULL );
154  assert( SCIPisFeasGT(scip, mostinfinf, 0.0) ); /* otherwise all variables are fixed and there is nothing to branch */
155 
156  /* branch */
157  SCIPdebugMessage("branching on variable %s with value %f and score %f\n", SCIPvarGetName(mostinfvar), mostinfval, mostinfscore);
158  SCIP_CALL( SCIPbranchVarVal(scip, mostinfvar, mostinfval, NULL, NULL, NULL) );
159 
160  *result = SCIP_BRANCHED;
161 
162  return SCIP_OKAY;
163 }
164 
165 /*
166  * branching rule specific interface methods
167  */
168 
171  SCIP* scip
172  )
173 {
174  SCIP_BRANCHRULEDATA* branchruledata;
175  SCIP_BRANCHRULE* branchrule;
176 
177  /* create empty branching rule data */
178  branchruledata = NULL;
179 
180  branchrule = NULL;
181 
182  /* include branching rule */
183  SCIP_CALL( SCIPincludeBranchruleBasic(scip, &branchrule, BRANCHRULE_NAME, BRANCHRULE_DESC, BRANCHRULE_PRIORITY,
184  BRANCHRULE_MAXDEPTH, BRANCHRULE_MAXBOUNDDIST, branchruledata) );
185 
186  assert(branchrule != NULL);
187 
188  /* set non fundamental callbacks via setter functions */
189  SCIP_CALL( SCIPsetBranchruleCopy(scip, branchrule, branchCopySdpmostinf) );
190  SCIP_CALL( SCIPsetBranchruleExecExt(scip, branchrule, branchExecextSdpmostinf) );
191 
192  return SCIP_OKAY;
193 }
#define BRANCHRULE_MAXBOUNDDIST
SCIP_RETCODE SCIPincludeBranchruleSdpmostinf(SCIP *scip)
most infeasible branching rule for SCIP-SDP
#define BRANCHRULE_PRIORITY
static SCIP_DECL_BRANCHEXECEXT(branchExecextSdpmostinf)
#define BRANCHRULE_NAME
#define BRANCHRULE_MAXDEPTH
static SCIP_DECL_BRANCHCOPY(branchCopySdpmostinf)
#define BRANCHRULE_DESC