Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2205_OptimizationNetworks/HeuristicLab.Problems.FacilityLocation.CplexSolver/3.3/FLPDataSource.cs @ 17842

Last change on this file since 17842 was 14595, checked in by abeham, 8 years ago

#2205: Added OPL model for for the capacitated FLP (by vhauder) and a HeuristicLab algorithm to solve the model through CPLEX

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 System;
23using HeuristicLab.Data;
24using ILOG.OPL;
25
26namespace HeuristicLab.Problems.FacilityLocation.CplexSolver {
27  public class FLPDataSource : CustomOplDataSource {
28    #region Inputs
29    public const string TotalDepots = "I";
30    public const string TotalCustomers = "J";
31    public const string OpeningCosts = "f";
32    public const string DepotCapacities = "s";
33    public const string CustomerDemands = "d";
34    public const string DeliveryCosts = "c";
35    #endregion
36    #region Variables
37    public const string CustomerDepotDeliverAmount = "x";
38    public const string DepotOpening = "y";
39    public const string CustomerDepotAssignment = "z";
40    #endregion
41
42    private FacilityLocationProblem problem;
43
44    public FLPDataSource(OplFactory factory, FacilityLocationProblem problem) : base(factory) {
45      this.problem = problem;
46    }
47
48    public override void CustomRead() {
49      NewElement(TotalDepots, () => Add(problem.DepotCapacitiesParameter.Value.Length));
50      NewElement(TotalCustomers, () => Add(problem.CustomerDemandsParameter.Value.Length));
51      NewElement(OpeningCosts, () => Add(problem.OpeningCostsParameter.Value));
52      NewElement(DepotCapacities, () => Add(problem.DepotCapacitiesParameter.Value));
53      NewElement(CustomerDemands, () => Add(problem.CustomerDemandsParameter.Value));
54      NewElement(DeliveryCosts, () => Add(problem.DeliveryCostsParameter.Value));
55    }
56
57    protected void NewElement(string name, Action add) {
58      DataHandler.StartElement(name);
59      add();
60      DataHandler.EndElement();
61    }
62    protected void Add(int value) {
63      DataHandler.AddIntItem(value);
64    }
65    protected void Add(double value) {
66      DataHandler.AddNumItem(value);
67    }
68    protected void Add(DoubleArray values) {
69      DataHandler.StartArray();
70      foreach (double value in values) {
71        DataHandler.AddNumItem(value);
72      }
73      DataHandler.EndArray();
74    }
75    protected void Add(DoubleMatrix values) {
76      DataHandler.StartArray();
77      for (var i = 0; i < values.Rows; i++) {
78        DataHandler.StartArray();
79        for (var j = 0; j < values.Columns; j++) {
80          Add(values[i, j]);
81        }
82        DataHandler.EndArray();
83      }
84      DataHandler.EndArray();
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.