#region License Information /* HeuristicLab * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using ILOG.CPLEX; using ILOG.OPL; namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.CPLEX { [Item("FY-Linearization CPLEX (GQAP)", "")] [StorableClass] [Creatable(CreatableAttribute.Categories.Algorithms)] public sealed class GQAP_FY : CplexSolver { [StorableConstructor] private GQAP_FY(bool deserializing) : base(deserializing) { } private GQAP_FY(GQAP_FY original, Cloner cloner) : base(original, cloner) { } public GQAP_FY() { } public override IDeepCloneable Clone(Cloner cloner) { return new GQAP_FY(this, cloner); } protected override OplModel GetModel(OplFactory factory, OplSettings settings, Cplex cplex) { using (var modelSource = factory.CreateOplModelSourceFromString(model, "gqap_fy")) using (var def = factory.CreateOplModelDefinition(modelSource, settings)) return factory.CreateOplModel(def, cplex); } private const string model = @"/********************************************* * OPL 12.7.0.0 Model * Author: Andreas Beham * Creation Date: 31.10.2017 at 14:30:01 *********************************************/ int EQUIPMENTS = ...; int LOCATIONS = ...; float TC = ...; range N = 1..EQUIPMENTS; range M = 1..LOCATIONS; float weights[N][N] = ...; float distances[M][M] = ...; float install[N][M] = ...; float demands[N] = ...; float capacities[M] = ...; dvar int+ x[N][M] in 0..1; dvar float+ z[N][M][N][M] in 0..1; dexpr float installCosts = sum(i in N, k in M) x[i][k] * install[i][k]; dexpr float flowCosts = TC * sum(i in 1..EQUIPMENTS-1, k in M, j in N, h in M: j > i) (weights[i][j] * distances[k][h] + weights[j][i] * distances[h][k]) * z[i][k][j][h]; minimize installCosts + flowCosts; subject to { forall (i in N) AllAssigned: sum(k in M) x[i][k] == 1; forall (k in M) Capacity: sum(i in N) x[i][k] * demands[i] <= capacities[k]; forall (i in 1..EQUIPMENTS-1, k in M, j in N: j > i) sum(h in M) z[i][k][j][h] == x[i][k]; forall (i in 1..EQUIPMENTS-1, j in N, h in M: j > i) sum(k in M) z[i][k][j][h] == x[j][h]; } "; } }