[15574] | 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 |
|
---|
[16728] | 22 | using HEAL.Attic;
|
---|
[15574] | 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using ILOG.CPLEX;
|
---|
| 26 | using ILOG.OPL;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.CPLEX {
|
---|
| 29 | [Item("FY-Linearization CPLEX (GQAP)", "")]
|
---|
[16728] | 30 | [StorableType("C10D185E-B007-4C9F-9EFC-6EE1D44A3DE1")]
|
---|
[15574] | 31 | [Creatable(CreatableAttribute.Categories.Algorithms)]
|
---|
| 32 | public sealed class GQAP_FY : CplexSolver {
|
---|
| 33 |
|
---|
| 34 | [StorableConstructor]
|
---|
[16728] | 35 | private GQAP_FY(StorableConstructorFlag _) : base(_) { }
|
---|
[15574] | 36 | private GQAP_FY(GQAP_FY original, Cloner cloner)
|
---|
| 37 | : base(original, cloner) {
|
---|
| 38 | }
|
---|
| 39 | public GQAP_FY() {
|
---|
| 40 |
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 44 | return new GQAP_FY(this, cloner);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | protected override OplModel GetModel(OplFactory factory, OplSettings settings, Cplex cplex) {
|
---|
| 48 | using (var modelSource = factory.CreateOplModelSourceFromString(model, "gqap_fy"))
|
---|
| 49 | using (var def = factory.CreateOplModelDefinition(modelSource, settings))
|
---|
| 50 | return factory.CreateOplModel(def, cplex);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[15575] | 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 | *********************************************/
|
---|
[15574] | 58 |
|
---|
[15575] | 59 | int EQUIPMENTS = ...;
|
---|
| 60 | int LOCATIONS = ...;
|
---|
| 61 | float TC = ...;
|
---|
| 62 |
|
---|
| 63 | range N = 1..EQUIPMENTS;
|
---|
| 64 | range M = 1..LOCATIONS;
|
---|
| 65 |
|
---|
[15604] | 66 | float weights[N][N] = ...;
|
---|
| 67 | float distances[M][M] = ...;
|
---|
| 68 | float install[N][M] = ...;
|
---|
| 69 | float demands[N] = ...;
|
---|
| 70 | float capacities[M] = ...;
|
---|
[15575] | 71 |
|
---|
| 72 | dvar int+ x[N][M] in 0..1;
|
---|
| 73 | dvar float+ z[N][M][N][M] in 0..1;
|
---|
| 74 |
|
---|
| 75 | dexpr float installCosts = sum(i in N, k in M) x[i][k] * install[i][k];
|
---|
| 76 | dexpr float flowCosts = TC * sum(i in 1..EQUIPMENTS-1, k in M, j in N, h in M: j > i)
|
---|
| 77 | (weights[i][j] * distances[k][h] + weights[j][i] * distances[h][k]) * z[i][k][j][h];
|
---|
| 78 |
|
---|
| 79 | minimize installCosts + flowCosts;
|
---|
| 80 |
|
---|
| 81 | subject to {
|
---|
| 82 |
|
---|
| 83 | forall (i in N)
|
---|
| 84 | AllAssigned:
|
---|
| 85 | sum(k in M) x[i][k] == 1;
|
---|
| 86 |
|
---|
| 87 | forall (k in M)
|
---|
| 88 | Capacity:
|
---|
| 89 | sum(i in N) x[i][k] * demands[i] <= capacities[k];
|
---|
| 90 |
|
---|
| 91 | forall (i in 1..EQUIPMENTS-1, k in M, j in N: j > i)
|
---|
| 92 | sum(h in M) z[i][k][j][h] == x[i][k];
|
---|
| 93 |
|
---|
| 94 | forall (i in 1..EQUIPMENTS-1, j in N, h in M: j > i)
|
---|
| 95 | sum(k in M) z[i][k][j][h] == x[j][h];
|
---|
| 96 |
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[15574] | 99 | ";
|
---|
| 100 | }
|
---|
| 101 | }
|
---|