Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/CPLEX/GQAP-FY.cs @ 15604

Last change on this file since 15604 was 15604, checked in by abeham, 6 years ago

#1614: fixed data type of inputs in FY model

File size: 3.1 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25using ILOG.CPLEX;
26using ILOG.OPL;
27
28namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.CPLEX {
29  [Item("FY-Linearization CPLEX (GQAP)", "")]
30  [StorableClass]
31  [Creatable(CreatableAttribute.Categories.Algorithms)]
32  public sealed class GQAP_FY : CplexSolver {
33   
34    [StorableConstructor]
35    private GQAP_FY(bool deserializing) : base(deserializing) { }
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
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
59int EQUIPMENTS = ...;
60int LOCATIONS = ...;
61float TC = ...;
62
63range N = 1..EQUIPMENTS;
64range M = 1..LOCATIONS;
65
66float weights[N][N] = ...;
67float distances[M][M] = ...;
68float install[N][M] = ...;
69float demands[N] = ...;
70float capacities[M] = ...;
71
72dvar int+ x[N][M] in 0..1;
73dvar float+ z[N][M][N][M] in 0..1;
74
75dexpr float installCosts = sum(i in N, k in M) x[i][k] * install[i][k];
76dexpr 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
79minimize installCosts + flowCosts;
80 
81subject to {
82
83forall (i in N)
84  AllAssigned:
85  sum(k in M) x[i][k] == 1;
86
87forall (k in M)
88  Capacity:
89  sum(i in N) x[i][k] * demands[i] <= capacities[k];
90
91forall (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
94forall (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
99";
100  }
101}
Note: See TracBrowser for help on using the repository browser.