#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("KB-Linearization CPLEX (GQAP)", "")] [StorableClass] [Creatable(CreatableAttribute.Categories.Algorithms)] public sealed class GQAP_KB : CplexSolver { [StorableConstructor] private GQAP_KB(bool deserializing) : base(deserializing) { } private GQAP_KB(GQAP_KB original, Cloner cloner) : base(original, cloner) { } public GQAP_KB() { } public override IDeepCloneable Clone(Cloner cloner) { return new GQAP_KB(this, cloner); } protected override OplModel GetModel(OplFactory factory, OplSettings settings, Cplex cplex) { using (var modelSource = factory.CreateOplModelSourceFromString(model, "gqap_kb")) 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] = ...; float v[i in N][k in M] = sum(j in N, h in M) (weights[i][j] * distances[k][h]); dvar int+ x[N][M] in 0..1; dvar float+ y[N][M]; dexpr float installCosts = sum(i in N, k in M) x[i][k] * install[i][k]; dexpr float flowCosts = TC * sum(i in N, k in M) y[i][k]; 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 N, k in M) 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]; } "; } }