SCIP Doxygen Documentation
 
Loading...
Searching...
No Matches
cpoptimizer.cpp
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-2024 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file cpoptimizer.cpp
26 * @brief contains method to solve a single cumulative condition via IBM ILOG CP Optimiter
27 * @author Stefan Heinz
28 */
29
30/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31
32#ifdef WITH_CPOPTIMIZER
33
34#include <ilcp/cp.h>
35
36#include "cpoptimizer.h"
37
38/** solve single cumulative condition using CP Optimizer */
40{
41 IloEnv env;
42
43 (*solved) = FALSE;
44 (*infeasible) = FALSE;
45 (*unbounded) = FALSE;
46 (*error) = FALSE;
47
48 try
49 {
50 int totaldemand;
51 int v;
52
53 IloModel model(env);
54 IloIntervalVarArray jobs(env, njobs);
55
56 IloCumulFunctionExpr cumulative = IloCumulFunctionExpr(env);
57 IloNumExpr costs(env);
58
59 totaldemand = 0;
60
61 for( v = 0; v < njobs; ++v )
62 {
63 jobs[v] = IloIntervalVar(env);
64
65 /* set bounds */
66 jobs[v].setStartMin(ests[v]);
67 jobs[v].setEndMax(lsts[v] + durations[v]);
68
69 /* set job duration */
70 jobs[v].setSizeMin(durations[v]);
71 jobs[v].setSizeMax(durations[v]);
72
73 /* add job to cumulative constraint with corresponding demand */
74 cumulative += IloPulse(jobs[v], demands[v]);
75
76 if( objvals != NULL )
77 costs += IloStartOf(jobs[v]) * objvals[v];
78
79 totaldemand += demands[v];
80 }
81
82
83 if( totaldemand <= capacity && objvals == NULL )
84 {
85 for( v = 0; v < njobs; ++v )
86 lsts[v] = ests[v];
87
88 (*solved) = TRUE;
89
90 return SCIP_OKAY;
91 }
92
93 /* add objective */
94 IloObjective objective(env);
95 objective.setExpr(costs);
96 objective.setSense(IloObjective::Minimize);
97
98
99 /* add cumulative constraint to the model */
100
101 IloIntervalVar horizon(env);
102 horizon.setStartMin(hmin);
103 horizon.setEndMax(hmax);
104 horizon.setSizeMin(hmax - hmin);
105 horizon.setSizeMax(hmax - hmin);
106
107 cumulative += IloPulse(horizon, totaldemand - capacity);
108 model.add(cumulative <= totaldemand);
109
110 IloCP cp(model);
111
112 /* set time limit */
113 cp.setParameter(IloCP::TimeLimit, timelimit);
114
115 if( maxnodes >= 0 )
116 cp.setParameter(IloCP::ChoicePointLimit, maxnodes);
117
118 cp.setParameter(IloCP::LogVerbosity, IloCP::Quiet);
119
120 cp.setParameter(IloCP::SearchType, IloCP::DepthFirst);
121 cp.setParameter(IloCP::CumulFunctionInferenceLevel, IloCP::Extended);
122 cp.setParameter(IloCP::NoOverlapInferenceLevel, IloCP::Extended);
123 cp.setParameter(IloCP::Workers, 1); // Use only one CPU
124
125 cp.solve();
126
127 switch( cp.getStatus() )
128 {
129 case IloAlgorithm::Feasible:
130 case IloAlgorithm::Optimal:
131 /* collect optimal solution */
132 for( v = 0; v < njobs; ++v )
133 {
134 ests[v] = cp.getStart(jobs[v]);
135 lsts[v] = cp.getStart(jobs[v]);
136 }
137 (*solved) = TRUE;
138 break;
139 case IloAlgorithm::InfeasibleOrUnbounded:
140 (*infeasible) = TRUE;
141 (*unbounded) = TRUE;
142 (*solved) = TRUE;
143 abort();
144 break;
145 case IloAlgorithm::Infeasible:
146 (*infeasible) = TRUE;
147 (*solved) = TRUE;
148 break;
149 case IloAlgorithm::Unbounded:
150 (*unbounded) = TRUE;
151 break;
152 case IloAlgorithm::Unknown:
153 case IloAlgorithm::Error:
154 (*error) = TRUE;
155 break;
156 }
157 }
158 catch( IloException& e )
159 {
160 SCIPerrorMessage("CP Optimizer Execution <%s>\n",e.getMessage());
161 (*error) = TRUE;
162 }
163
164 env.end();
165
166 return SCIP_OKAY;
167}
168
169#endif
contains method to solve a single cumulative condition via IBM ILOG CP Optimiter
#define NULL
Definition def.h:266
#define TRUE
Definition def.h:93
#define FALSE
Definition def.h:94
#define SCIP_DECL_SOLVECUMULATIVE(x)
return SCIP_OKAY
#define SCIPerrorMessage
Definition pub_message.h:64