Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/CPLEX/GQAP-KB.cs @ 17712

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

#1614: updated to new persistence and .NET 4.6.1

File size: 3.0 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 HEAL.Attic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using ILOG.CPLEX;
26using ILOG.OPL;
27
28namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.CPLEX {
29  [Item("KB-Linearization CPLEX (GQAP)", "")]
30  [StorableType("649D3DB6-3E54-46E7-BB12-5F26417D6E40")]
31  [Creatable(CreatableAttribute.Categories.Algorithms)]
32  public sealed class GQAP_KB : CplexSolver {
33   
34    [StorableConstructor]
35    private GQAP_KB(StorableConstructorFlag _) : base(_) { }
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
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
72float v[i in N][k in M] = sum(j in N, h in M) (weights[i][j] * distances[k][h]);
73
74dvar int+ x[N][M] in 0..1;
75dvar float+ y[N][M];
76
77dexpr float installCosts = sum(i in N, k in M) x[i][k] * install[i][k];
78dexpr float flowCosts = TC * sum(i in N, k in M) y[i][k];
79
80minimize installCosts + flowCosts;
81 
82subject to {
83
84forall (i in N)
85  AllAssigned:
86  sum(k in M) x[i][k] == 1;
87
88forall (k in M)
89  Capacity:
90  sum(i in N) x[i][k] * demands[i] <= capacities[k];
91
92forall (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}
Note: See TracBrowser for help on using the repository browser.