Scippy

SCIP

Solving Constraint Integer Programs

relax_lp.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2017 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file relax_lp.c
17  * @brief lp relaxator
18  * @author Benjamin Mueller
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <assert.h>
24 
25 #include "relax_lp.h"
26 
27 #define RELAX_NAME "lp"
28 #define RELAX_DESC "relaxator solving LP relaxation"
29 #define RELAX_PRIORITY 0
30 #define RELAX_FREQ 0
31 #define RELAX_FULLLPINFO TRUE
32 
33 
34 /*
35  * Data structures
36  */
37 
38 
39 /*
40  * Local methods
41  */
42 
43 
44 /*
45  * Callback methods of relaxator
46  */
47 
48 /** execution method of relaxator */
49 static
50 SCIP_DECL_RELAXEXEC(relaxExecLp)
51 { /*lint --e{715}*/
52  SCIP* relaxscip;
53  SCIP_HASHMAP* varmap;
54  SCIP_Real relaxval;
55  SCIP_Bool valid;
56  int i;
57 
58  *lowerbound = -SCIPinfinity(scip);
59  *result = SCIP_DIDNOTRUN;
60 
61  /* create the variable mapping hash map */
62  SCIP_CALL( SCIPcreate(&relaxscip) );
63  SCIP_CALL( SCIPhashmapCreate(&varmap, SCIPblkmem(relaxscip), SCIPgetNVars(scip)) );
64  valid = FALSE;
65  SCIP_CALL( SCIPcopy(scip, relaxscip, varmap, NULL, "relaxscip", FALSE, FALSE, FALSE, &valid) );
66 
67  /* change variable types */
68  for( i = 0; i < SCIPgetNVars(relaxscip); ++i )
69  {
70  SCIP_VAR* var;
71  SCIP_Bool infeasible;
72 
73  var = SCIPgetVars(relaxscip)[i];
74  assert(var != NULL);
75 
76  SCIP_CALL( SCIPchgVarType(relaxscip, var, SCIP_VARTYPE_CONTINUOUS, &infeasible) );
77  assert(!infeasible);
78  }
79 
80  SCIPsetMessagehdlrQuiet(relaxscip, TRUE);
81  SCIP_CALL( SCIPtransformProb(relaxscip) );
82  SCIP_CALL( SCIPsolve(relaxscip) );
83 
84  relaxval = SCIPgetPrimalbound(relaxscip);
85  SCIPdebugMessage("relaxation bound = %e status = %d\n", relaxval, SCIPgetStatus(relaxscip));
86 
87  if( SCIPgetStatus(relaxscip) == SCIP_STATUS_OPTIMAL )
88  {
89  *lowerbound = relaxval;
90  *result = SCIP_SUCCESS;
91 
92  /* store relaxation solution in original SCIP */
93  for( i = 0; i < SCIPgetNVars(scip); ++i )
94  {
95  SCIP_VAR* relaxvar;
96  SCIP_Real solval;
97 
98  relaxvar = SCIPhashmapGetImage(varmap, SCIPgetVars(scip)[i]);
99  assert(relaxvar != NULL);
100 
101  solval = SCIPgetSolVal(relaxscip, SCIPgetBestSol(relaxscip), relaxvar);
102 
104  }
105 
106  /* mark relaxation solution to be valid */
108  }
109 
110  /* free memory */
111  SCIPhashmapFree(&varmap);
112  SCIP_CALL( SCIPfree(&relaxscip) );
113 
114  return SCIP_OKAY;
115 }
116 
117 
118 /*
119  * relaxator specific interface methods
120  */
121 
122 /** creates the lp relaxator and includes it in SCIP */
124  SCIP* scip /**< SCIP data structure */
125  )
126 {
127  SCIP_RELAXDATA* relaxdata;
128  SCIP_RELAX* relax;
129 
130  /* create lp relaxator data */
131  relaxdata = NULL;
132  relax = NULL;
133 
134  /* include relaxator */
136  relaxExecLp, relaxdata) );
137  assert(relax != NULL);
138 
139  return SCIP_OKAY;
140 }
SCIP_Real SCIPgetPrimalbound(SCIP *scip)
Definition: scip.c:42448
#define FALSE
Definition: def.h:64
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:2765
SCIP_RETCODE SCIPincludeRelaxLp(SCIP *scip)
Definition: relax_lp.c:123
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:45816
static SCIP_DECL_RELAXEXEC(relaxExecLp)
Definition: relax_lp.c:50
#define TRUE
Definition: def.h:63
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIPdebugMessage
Definition: pub_message.h:77
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2903
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip.c:696
SCIP_RETCODE SCIPmarkRelaxSolValid(SCIP *scip)
Definition: scip.c:19679
#define RELAX_FREQ
Definition: relax_lp.c:30
SCIP_RETCODE SCIPchgVarType(SCIP *scip, SCIP_VAR *var, SCIP_VARTYPE vartype, SCIP_Bool *infeasible)
Definition: scip.c:25045
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip.c:15777
SCIP_STATUS SCIPgetStatus(SCIP *scip)
Definition: scip.c:921
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip.c:45519
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:2798
lp relaxator
#define NULL
Definition: lpi_spx1.cpp:137
#define SCIP_CALL(x)
Definition: def.h:306
#define SCIP_Bool
Definition: def.h:61
#define RELAX_FULLLPINFO
Definition: relax_lp.c:31
void SCIPsetMessagehdlrQuiet(SCIP *scip, SCIP_Bool quiet)
Definition: scip.c:1248
#define RELAX_NAME
Definition: relax_lp.c:27
int SCIPgetNVars(SCIP *scip)
Definition: scip.c:11631
SCIP_RETCODE SCIPincludeRelaxBasic(SCIP *scip, SCIP_RELAX **relaxptr, const char *name, const char *desc, int priority, int freq, SCIP_Bool includeslp, SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
Definition: scip.c:7087
SCIP_RETCODE SCIPsetRelaxSolVal(SCIP *scip, SCIP_VAR *var, SCIP_Real val)
Definition: scip.c:19545
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip.c:38931
struct SCIP_RelaxData SCIP_RELAXDATA
Definition: type_relax.h:38
SCIP_RETCODE SCIPcopy(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_Bool global, SCIP_Bool enablepricing, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
Definition: scip.c:3757
#define RELAX_DESC
Definition: relax_lp.c:28
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip.c:11586
#define SCIP_Real
Definition: def.h:135
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
Definition: scip.c:13668
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip.c:38007
#define RELAX_PRIORITY
Definition: relax_lp.c:29
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip.c:774