SCIP-SDP  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
branch_sdpmostfrac.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_sdpmostfrac.h"
46 
47 
48 #define BRANCHRULE_NAME "sdpmostfrac"
49 #define BRANCHRULE_DESC "branch on the most fractional variable of the SDP"
50 #define BRANCHRULE_PRIORITY 500000
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(branchCopySdpmostfrac)
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( SCIPincludeBranchruleSdpmostfrac(scip) );
80 
81  return SCIP_OKAY;
82 }
83 
85 static
86 SCIP_DECL_BRANCHEXECEXT(branchExecextSdpmostfrac)
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 mostfracfrac; /* fractionality of the current most fractional variable */
94  SCIP_Real mostfracscore; /* score of the current most fractional variable */
95  SCIP_Real mostfracobj; /* objective of the current most fractional variable */
96  SCIP_Real mostfracval; /* value of the current most fractional variable */
97  SCIP_VAR* mostfracvar = NULL; /* variable with the highest current fractionality */
98 
99 
100  assert( scip != NULL );
101  assert( result != NULL );
102 
103  SCIPdebugMessage("Executing External Branching method of SDP-mostfrac!\n");
104 
105  /* get the external candidates, as we use the score only as a tiebreaker, we aren't interested in the number of
106  * variables of different types with maximal score, so these return values are set to NULL */
107  SCIP_CALL( SCIPgetExternBranchCands(scip, &cands, &candssol, &candsscore, &ncands, NULL, NULL, NULL, NULL) );
108 
109  assert( ncands > 0 ); /* branchExecext should only be called if the list of extern branching candidate is non-empty */
110 
111 #ifdef SCIP_DEBUG
112  printf("branching candidates for SDP-mostfrac:\n");
113  for (i = 0; i < ncands; i++)
114  printf("%s, value = %f, score = %f\n", SCIPvarGetName(cands[i]), candssol[i], candsscore[i]);
115 #endif
116 
117  mostfracfrac = -1.0;
118  mostfracscore = 0.0;
119  mostfracval = 0.0;
120  mostfracobj = -1.0;
121 
122  /* iterate over all solution candidates to find the one with the highest fractionality */
123  for (i = 0; i < ncands; i++)
124  {
125  /* a candidate is better than the current one if:
126  * - the fractionality is (feastol-)bigger than before or
127  * - the fractionality is (feastol-)equal and the score is (epsilon-)bigger or
128  * - the fractionality and score are (feastol-/epsilon-)equal and the objective is bigger */
129  if ( SCIPisFeasGT(scip, SCIPfeasFrac(scip, candssol[i]), mostfracfrac) ||
130  (SCIPisFeasEQ(scip, SCIPfeasFrac(scip, candssol[i]), mostfracfrac) && SCIPisGT(scip, candsscore[i], mostfracscore)) ||
131  (SCIPisFeasEQ(scip, SCIPfeasFrac(scip, candssol[i]), mostfracfrac) && SCIPisEQ(scip, candsscore[i], mostfracscore)
132  && REALABS(SCIPvarGetObj(cands[i])) > mostfracobj) )
133  {
134  /* update the current best candidate */
135  mostfracfrac = SCIPfeasFrac(scip, candssol[i]);
136  mostfracscore = candsscore[i];
137  mostfracobj = REALABS(SCIPvarGetObj(cands[i]));
138  mostfracval = candssol[i];
139  mostfracvar = cands[i];
140  }
141  }
142 
143  assert( mostfracvar != NULL );
144  assert( SCIPisFeasGT(scip, mostfracfrac, 0.0) ); /* otherwise all variables are fixed and there is nothing to branch */
145 
146  /* branch */
147  SCIPdebugMessage("branching on variable %s with value %f and score %f\n", SCIPvarGetName(mostfracvar), mostfracval, mostfracscore);
148  SCIP_CALL( SCIPbranchVarVal(scip, mostfracvar, mostfracval, NULL, NULL, NULL) );
149 
150  *result = SCIP_BRANCHED;
151 
152  return SCIP_OKAY;
153 }
154 
155 /*
156  * branching rule specific interface methods
157  */
158 
161  SCIP* scip
162 )
163 {
164  SCIP_BRANCHRULEDATA* branchruledata;
165  SCIP_BRANCHRULE* branchrule;
166 
167  /* create empty branching rule data */
168  branchruledata = NULL;
169 
170  branchrule = NULL;
171 
172  /* include branching rule */
173  SCIP_CALL( SCIPincludeBranchruleBasic(scip, &branchrule, BRANCHRULE_NAME, BRANCHRULE_DESC, BRANCHRULE_PRIORITY,
174  BRANCHRULE_MAXDEPTH, BRANCHRULE_MAXBOUNDDIST, branchruledata) );
175 
176  assert(branchrule != NULL);
177 
178  /* set non fundamental callbacks via setter functions */
179  SCIP_CALL( SCIPsetBranchruleCopy(scip, branchrule, branchCopySdpmostfrac) );
180  SCIP_CALL( SCIPsetBranchruleExecExt(scip, branchrule, branchExecextSdpmostfrac) );
181 
182  return SCIP_OKAY;
183 }
#define BRANCHRULE_MAXBOUNDDIST
#define BRANCHRULE_DESC
most fractional branching rule for SCIPSDP
SCIP_RETCODE SCIPincludeBranchruleSdpmostfrac(SCIP *scip)
#define BRANCHRULE_PRIORITY
#define BRANCHRULE_NAME
#define BRANCHRULE_MAXDEPTH
static SCIP_DECL_BRANCHCOPY(branchCopySdpmostfrac)
static SCIP_DECL_BRANCHEXECEXT(branchExecextSdpmostfrac)