1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /*                                                                           */
3 /*                  This file is part of the program and library             */
4 /*         SCIP --- Solving Constraint Integer Programs                      */
5 /*                                                                           */
6 /*    Copyright (C) 2002-2021 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 visit scipopt.org.         */
13 /*                                                                           */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file   disable_upgrades.c
17  * @brief  tests for or-constraint methods with upgrades to and-constraints disabled
18  * @author Gregor Hendel
19  * @author Helena Müller
20  */
21 
22 #include "scip/scip.h"
23 #include "include/scip_test.h"
24 #include "scip/scipdefplugins.h"
25 #include "scip/cons_or.h"
26 #include "scip/pub_cons.h"
27 #include <stdio.h>
28 
29 /** GLOBAL VARIABLES **/
30 static SCIP* scip = NULL;
31 
32 
33 /* TEST SUITE */
34 
35 /** the setup creates the necessary source SCIP, sets parameter */
36 static
setup(void)37 void setup(void)
38 {
39    SCIP_CALL( SCIPcreate(&scip) );
40 
41    SCIP_CALL( SCIPincludeDefaultPlugins(scip) );
42 
43    SCIP_CALL( SCIPsetIntParam(scip, "constraints/or/maxprerounds", 0) );
44    SCIP_CALL( SCIPsetIntParam(scip, "presolving/maxrestarts", 0) );
45    SCIP_CALL( SCIPsetIntParam(scip, "branching/inference/priority", 1000000) );
46 
47    SCIP_CALL( SCIPsetHeuristics(scip, SCIP_PARAMSETTING_OFF, FALSE) );
48 }
49 
50 /** free all allocated memory */
51 static
teardown(void)52 void teardown(void)
53 {
54    SCIP_CALL( SCIPfree(&scip) );
55 
56 }
57 
58 
59 TestSuite(disable_upgrades, .init = setup, .fini = teardown);
60 
61 /* TESTS  */
Test(disable_upgrades,create_and_free)62 Test(disable_upgrades, create_and_free)
63 {
64    /* calls setup and teardown */
65 }
66 
67 Test(disable_upgrades, disable_upgrades_or, .description="disable upgrades of or-constraints to and-constraints to keep or-constraints during solution process")
68 {
69    SCIP_CONSHDLR* conshdlr;
70    SCIP_CONS** conss;
71    int nconss;
72    int i;
73 
74    SCIP_CALL( SCIPreadProb(scip, "../check/instances/Or/or_constraint.cip", "cip") );
75 
76    conshdlr = SCIPfindConshdlr(scip, "or");
77 
78    nconss = SCIPgetNOrigConss(scip);
79    conss = SCIPgetOrigConss(scip);
80 
81    cr_assert_eq(nconss, 8);
82 
83    /* set or-constraints to be modifiable */
84    for( i = 0; i < nconss; ++i )
85    {
86       if( SCIPconsGetHdlr(conss[i]) == conshdlr )
87          SCIPsetConsModifiable(scip, conss[i], TRUE);
88    }
89 
90    SCIP_CALL( SCIPchgVarUbGlobal(scip, SCIPgetVars(scip)[3], 0.0) );
91    SCIP_CALL( SCIPchgVarUbGlobal(scip, SCIPgetVars(scip)[4], 0.0) );
92    SCIP_CALL( SCIPchgVarUbGlobal(scip, SCIPgetVars(scip)[2], 0.0) );
93    SCIP_CALL( SCIPchgVarUbGlobal(scip, SCIPgetVars(scip)[1], 0.0) );
94 
95    SCIP_CALL( SCIPsetIntParam(scip, "constraints/or/maxprerounds", 1) );
96 
97    SCIP_CALL( SCIPsolve(scip) );
98 }
99 
100 Test(disable_upgrades, write_problem, .description="test that CIP write method works for or constraints")
101 {
102    SCIP_CALL( SCIPreadProb(scip, "../check/instances/Or/or_constraint.cip", "cip") );
103 
104    SCIP_CALL( SCIPwriteOrigProblem(scip, NULL, "cip", FALSE) );
105 }
106 
107 Test(disable_upgrades, copy_problem, .description="test copying of or-constraints")
108 {
109    SCIP* targetscip;
110    SCIP_Bool valid;
111    SCIP_CALL( SCIPreadProb(scip, "../check/instances/Or/or_constraint.cip", "cip") );
112 
113    SCIP_CALL( SCIPcreate(&targetscip) );
114 
115    SCIP_CALL( SCIPcopy(scip, targetscip, NULL, NULL, "copy_of_prob", TRUE, TRUE, FALSE, FALSE, &valid) );
116 
117    cr_assert(valid);
118 
119    SCIP_CALL( SCIPsolve(targetscip) );
120 
121    SCIP_CALL( SCIPfree(&targetscip) );
122 }
123 
124 Test(disable_upgrades, test_basic_creation, .description="test SCIPcreateConsBasicOr")
125 {
126    SCIP_CONS* newcons;
127    SCIP_VAR** origvars;
128 
129    SCIP_CALL( SCIPreadProb(scip, "../check/instances/Or/or_constraint.cip", "cip") );
130 
131    cr_assert(SCIPgetNVars(scip) == 24);
132    cr_assert(SCIPgetNBinVars(scip) == 24);
133 
134    origvars = SCIPgetOrigVars(scip);
135 
136    SCIP_CALL( SCIPcreateConsBasicOr(scip, &newcons, "new_or_constraint", origvars[3], 6, &origvars[4]) );
137 
138    SCIP_CALL( SCIPaddCons(scip, newcons) );
139 
140    SCIP_CALL( SCIPreleaseCons(scip, &newcons) );
141 
142    SCIP_CALL( SCIPsolve(scip) );
143 
144    SCIP_CALL( SCIPprintBestSol(scip, NULL, TRUE) );
145 
146 }
147