1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
25 | using ILOG.CPLEX;
|
---|
26 | using ILOG.OPL;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.CPLEX {
|
---|
29 | [Item("KB-Linearization CPLEX (GQAP)", "")]
|
---|
30 | [StorableClass]
|
---|
31 | [Creatable(CreatableAttribute.Categories.Algorithms)]
|
---|
32 | public sealed class GQAP_KB : CplexSolver {
|
---|
33 |
|
---|
34 | [StorableConstructor]
|
---|
35 | private GQAP_KB(bool deserializing) : base(deserializing) { }
|
---|
36 | private GQAP_KB(GQAP_KB original, Cloner cloner)
|
---|
37 | : base(original, cloner) {
|
---|
38 | }
|
---|
39 | public GQAP_KB() {
|
---|
40 |
|
---|
41 | }
|
---|
42 |
|
---|
43 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
44 | return new GQAP_KB(this, cloner);
|
---|
45 | }
|
---|
46 |
|
---|
47 | protected override OplModel GetModel(OplFactory factory, OplSettings settings, Cplex cplex) {
|
---|
48 | using (var modelSource = factory.CreateOplModelSourceFromString(model, "gqap_kb"))
|
---|
49 | using (var def = factory.CreateOplModelDefinition(modelSource, settings))
|
---|
50 | return factory.CreateOplModel(def, cplex);
|
---|
51 | }
|
---|
52 |
|
---|
53 | private const string model = @"/********************************************* |
---|
54 | * OPL 12.7.0.0 Model |
---|
55 | * Author: Andreas Beham |
---|
56 | * Creation Date: 31.10.2017 at 14:30:01 |
---|
57 | *********************************************/ |
---|
58 | |
---|
59 | int EQUIPMENTS = ...; |
---|
60 | int LOCATIONS = ...; |
---|
61 | float TC = ...; |
---|
62 | |
---|
63 | range N = 1..EQUIPMENTS; |
---|
64 | range M = 1..LOCATIONS; |
---|
65 | |
---|
66 | float weights[N][N] = ...; |
---|
67 | float distances[M][M] = ...; |
---|
68 | float install[N][M] = ...; |
---|
69 | float demands[N] = ...; |
---|
70 | float capacities[M] = ...; |
---|
71 | |
---|
72 | float v[i in N][k in M] = sum(j in N, h in M) (weights[i][j] * distances[k][h]); |
---|
73 | |
---|
74 | dvar int+ x[N][M] in 0..1; |
---|
75 | dvar float+ y[N][M]; |
---|
76 | |
---|
77 | dexpr float installCosts = sum(i in N, k in M) x[i][k] * install[i][k]; |
---|
78 | dexpr float flowCosts = TC * sum(i in N, k in M) y[i][k]; |
---|
79 | |
---|
80 | minimize installCosts + flowCosts; |
---|
81 | |
---|
82 | subject to { |
---|
83 | |
---|
84 | forall (i in N) |
---|
85 | AllAssigned: |
---|
86 | sum(k in M) x[i][k] == 1; |
---|
87 | |
---|
88 | forall (k in M) |
---|
89 | Capacity: |
---|
90 | sum(i in N) x[i][k] * demands[i] <= capacities[k]; |
---|
91 | |
---|
92 | forall (i in N, k in M) |
---|
93 | v[i][k] * ( x[i][k] - 1 ) + sum(j in N, h in M) (x[j][h] * weights[i][j] * distances[k][h]) <= y[i][k]; |
---|
94 | |
---|
95 | } |
---|
96 | |
---|
97 | ";
|
---|
98 | }
|
---|
99 | }
|
---|