SCIP-SDP  2.0.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-2015 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-2015 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 
38 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
39 
40 /*#define SCIP_DEBUG*/
41 
42 #include <assert.h>
43 #include <string.h>
44 
45 #include "branch_sdpmostinf.h"
46 
47 
48 #define BRANCHRULE_NAME "sdpmostinf"
49 #define BRANCHRULE_DESC "branch on the most infeasible variable of the SDP"
50 #define BRANCHRULE_PRIORITY 1000000
51 #define BRANCHRULE_MAXDEPTH -1
52 #define BRANCHRULE_MAXBOUNDDIST 1.0
53 
54 
55 /*
56  * Data structures
57  */
58 
59 /*
60  * Local methods
61  */
62 
63 /* put your local methods here, and declare them static */
64 
65 
66 /*
67  * Callback methods of branching rule
68  */
69 
71 static
72 SCIP_DECL_BRANCHCOPY(branchCopySdpmostinf)
73 { /*lint --e{715}*/
74  assert(scip != NULL);
75  assert(branchrule != NULL);
76  assert(strcmp(SCIPbranchruleGetName(branchrule), BRANCHRULE_NAME) == 0);
77 
78  /* call inclusion method of branchrule */
79  SCIP_CALL( SCIPincludeBranchruleSdpmostinf(scip) );
80 
81  return SCIP_OKAY;
82 }
83 
85 static
86 SCIP_DECL_BRANCHEXECEXT(branchExecextSdpmostinf)
87 {/*lint --e{715}*/
88  int i;
89  int ncands;
90  SCIP_VAR** cands = NULL;
91  SCIP_Real* candssol; /* solution values of all candidates */
92  SCIP_Real* candsscore; /* scores of all candidates */
93  SCIP_Real currentfrac; /* fractionality of the current candidate */
94  SCIP_Real currentinf; /* infeasibility of the current candidate */
95  SCIP_Real mostinfinf; /* infeasibility of the current most infeasible variable */
96  SCIP_Real mostinfscore; /* score of the current most infeasible variable */
97  SCIP_Real mostinfobj; /* objective of the current most infeasible variable */
98  SCIP_Real mostinfval; /* value of the current most infeasible variable */
99  SCIP_VAR* mostinfvar = NULL; /* variable with the highest current infeasibility */
100 
101 
102  assert( scip != NULL );
103  assert( result != NULL );
104 
105  SCIPdebugMessage("Executing External Branching method of SDP-mostinf!\n");
106 
107  /* get the external candidates, as we use the score only as a tiebreaker, we aren't interested in the number of
108  * variables of different types with maximal score, so these return values are set to NULL */
109  SCIP_CALL( SCIPgetExternBranchCands(scip, &cands, &candssol, &candsscore, &ncands, NULL, NULL, NULL, NULL) );
110 
111  assert( ncands > 0 ); /* branchExecext should only be called if the list of extern branching candidate is non-empty */
112 
113 #ifdef SCIP_DEBUG
114  printf("branching candidates for SDP-mostinf:\n");
115  for (i = 0; i < ncands; i++)
116  printf("%s, value = %f, score = %f\n", SCIPvarGetName(cands[i]), candssol[i], candsscore[i]);
117 #endif
118 
119  mostinfinf = -1.0;
120  mostinfscore = 0.0;
121  mostinfval = 0.0;
122  mostinfobj = -1.0;
123 
124  /* iterate over all solution candidates to find the one with the highest infeasibility */
125  for (i = 0; i < ncands; i++)
126  {
127  currentfrac = SCIPfeasFrac(scip, candssol[i]);
128  currentinf = (currentfrac <= 0.5) ? currentfrac : 1 - currentfrac;
129  /* a candidate is better than the current one if:
130  * - the infeasibility is (feastol-)bigger than before or
131  * - the infeasibility is (feastol-)equal and the score is (epsilon-)bigger or
132  * - the infeasibility and score are (feastol-/epsilon-)equal and the objective is bigger than before */
133  if ( SCIPisFeasGT(scip, currentinf, mostinfinf) ||
134  (SCIPisFeasEQ(scip, currentinf, mostinfinf) && SCIPisGT(scip, candsscore[i], mostinfscore)) ||
135  (SCIPisFeasEQ(scip, currentinf, mostinfinf) && SCIPisEQ(scip, candsscore[i], mostinfscore) && REALABS(SCIPvarGetObj(cands[i])) > mostinfobj ) )
136  {
137  /* update the current best candidate */
138  mostinfinf = currentinf;
139  mostinfval = candssol[i];
140  mostinfobj = REALABS(SCIPvarGetObj(cands[i]));
141  mostinfscore = candsscore[i];
142  mostinfvar = cands[i];
143  }
144  }
145 
146  assert( mostinfvar != NULL );
147  assert( SCIPisFeasGT(scip, mostinfinf, 0.0) ); /* otherwise all variables are fixed and there is nothing to branch */
148 
149  /* branch */
150  SCIPdebugMessage("branching on variable %s with value %f and score %f\n", SCIPvarGetName(mostinfvar), mostinfval, mostinfscore);
151  SCIP_CALL( SCIPbranchVarVal(scip, mostinfvar, mostinfval, NULL, NULL, NULL) );
152 
153  *result = SCIP_BRANCHED;
154 
155  return SCIP_OKAY;
156 }
157 
158 /*
159  * branching rule specific interface methods
160  */
161 
164  SCIP* scip
165 )
166 {
167  SCIP_BRANCHRULEDATA* branchruledata;
168  SCIP_BRANCHRULE* branchrule;
169 
170  /* create empty branching rule data */
171  branchruledata = NULL;
172 
173  branchrule = NULL;
174 
175  /* include branching rule */
176  SCIP_CALL( SCIPincludeBranchruleBasic(scip, &branchrule, BRANCHRULE_NAME, BRANCHRULE_DESC, BRANCHRULE_PRIORITY,
177  BRANCHRULE_MAXDEPTH, BRANCHRULE_MAXBOUNDDIST, branchruledata) );
178 
179  assert(branchrule != NULL);
180 
181  /* set non fundamental callbacks via setter functions */
182  SCIP_CALL( SCIPsetBranchruleCopy(scip, branchrule, branchCopySdpmostinf) );
183  SCIP_CALL( SCIPsetBranchruleExecExt(scip, branchrule, branchExecextSdpmostinf) );
184 
185  return SCIP_OKAY;
186 }
#define BRANCHRULE_MAXBOUNDDIST
SCIP_RETCODE SCIPincludeBranchruleSdpmostinf(SCIP *scip)
most infeasible branching rule for SCIPSDP
#define BRANCHRULE_PRIORITY
static SCIP_DECL_BRANCHEXECEXT(branchExecextSdpmostinf)
#define BRANCHRULE_NAME
#define BRANCHRULE_MAXDEPTH
static SCIP_DECL_BRANCHCOPY(branchCopySdpmostinf)
#define BRANCHRULE_DESC