Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/CPLEX/GQAPDataSource.cs @ 15718

Last change on this file since 15718 was 15574, checked in by abeham, 6 years ago

#1614: Added CPLEX algorithms

File size: 2.6 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.GeneralizedQuadraticAssignment.Algorithms.CPLEX {
27  public class GQAPDataSource : CustomOplDataSource {
28    protected GQAPInstance Instance { get; set; }
29
30    public GQAPDataSource(OplFactory factory, GQAPInstance instance)
31      : base(factory) {
32      Instance = instance;
33    }
34
35    public override void CustomRead() {
36      NewElement("EQUIPMENTS", () => Add(Instance.Demands.Length));
37      NewElement("LOCATIONS", () => Add(Instance.Capacities.Length));
38      NewElement("TC", () => Add(Instance.TransportationCosts));
39      NewElement("weights", () => Add(Instance.Weights));
40      NewElement("distances", () => Add(Instance.Distances));
41      NewElement("install", () => Add(Instance.InstallationCosts));
42      NewElement("demands", () => Add(Instance.Demands));
43      NewElement("capacities", () => Add(Instance.Capacities));
44    }
45
46    protected void NewElement(string name, Action add) {
47      DataHandler.StartElement(name);
48      add();
49      DataHandler.EndElement();
50    }
51    protected void Add(int value) {
52      DataHandler.AddIntItem(value);
53    }
54    protected void Add(double value) {
55      DataHandler.AddNumItem(value);
56    }
57
58    protected void Add(DoubleArray values) {
59      DataHandler.StartArray();
60      for (var i = 0; i < values.Length; i++) {
61        Add(values[i]);
62      }
63      DataHandler.EndArray();
64    }
65
66    protected void Add(DoubleMatrix values) {
67      DataHandler.StartArray();
68      for (var i = 0; i < values.Rows; i++) {
69        DataHandler.StartArray();
70        for (var j = 0; j < values.Columns; j++) {
71          Add(values[i, j]);
72        }
73        DataHandler.EndArray();
74      }
75      DataHandler.EndArray();
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.