#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 System; using HeuristicLab.Data; using ILOG.OPL; namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.CPLEX { public class GQAPDataSource : CustomOplDataSource { protected GQAPInstance Instance { get; set; } public GQAPDataSource(OplFactory factory, GQAPInstance instance) : base(factory) { Instance = instance; } public override void CustomRead() { NewElement("EQUIPMENTS", () => Add(Instance.Demands.Length)); NewElement("LOCATIONS", () => Add(Instance.Capacities.Length)); NewElement("TC", () => Add(Instance.TransportationCosts)); NewElement("weights", () => Add(Instance.Weights)); NewElement("distances", () => Add(Instance.Distances)); NewElement("install", () => Add(Instance.InstallationCosts)); NewElement("demands", () => Add(Instance.Demands)); NewElement("capacities", () => Add(Instance.Capacities)); } protected void NewElement(string name, Action add) { DataHandler.StartElement(name); add(); DataHandler.EndElement(); } protected void Add(int value) { DataHandler.AddIntItem(value); } protected void Add(double value) { DataHandler.AddNumItem(value); } protected void Add(DoubleArray values) { DataHandler.StartArray(); for (var i = 0; i < values.Length; i++) { Add(values[i]); } DataHandler.EndArray(); } protected void Add(DoubleMatrix values) { DataHandler.StartArray(); for (var i = 0; i < values.Rows; i++) { DataHandler.StartArray(); for (var j = 0; j < values.Columns; j++) { Add(values[i, j]); } DataHandler.EndArray(); } DataHandler.EndArray(); } } }