1  #region License Information


2  /* HeuristicLab


3  * Copyright (C) 20022017 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 


22  using HeuristicLab.Common;


23  using HeuristicLab.Core;


24  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;


25  using ILOG.CPLEX;


26  using ILOG.OPL;


27 


28  namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.CPLEX {


29  [Item("FYLinearization 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 


59  int EQUIPMENTS = ...;


60  int LOCATIONS = ...;


61  float TC = ...;


62 


63  range N = 1..EQUIPMENTS;


64  range M = 1..LOCATIONS;


65 


66  int weights[N][N] = ...;


67  int distances[M][M] = ...;


68  int install[N][M] = ...;


69  int demands[N] = ...;


70  int capacities[M] = ...;


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..EQUIPMENTS1, 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..EQUIPMENTS1, 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..EQUIPMENTS1, 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  }

