#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 HEAL.Attic;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Parameters;
namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LocalSolverNet {
[Item("LocalSolver Context", "A context for CPLEX solvers.")]
[StorableType("DAE4D0C7-AFE1-4FCF-9DD5-899E4DC4FD9E")]
public class LocalSolverContext : SingleSolutionContext> {
[Storable]
private IValueParameter problem;
public GQAP Problem {
get { return problem.Value; }
set { problem.Value = value; }
}
[Storable]
private IValueParameter bestSolution;
public GQAPSolution BestSolution {
get { return bestSolution.Value; }
set { bestSolution.Value = value; }
}
[StorableConstructor]
protected LocalSolverContext(StorableConstructorFlag _) : base(_) { }
protected LocalSolverContext(LocalSolverContext original, Cloner cloner)
: base(original, cloner) {
problem = cloner.Clone(original.problem);
bestSolution = cloner.Clone(original.bestSolution);
}
public LocalSolverContext() : base() {
Parameters.Add(problem = new ValueParameter("Problem"));
Parameters.Add(bestSolution = new ValueParameter("BestFoundSolution"));
}
public LocalSolverContext(string name) : base(name) {
Parameters.Add(problem = new ValueParameter("Problem"));
Parameters.Add(bestSolution = new ValueParameter("BestFoundSolution"));
}
public LocalSolverContext(string name, ParameterCollection parameters) : base(name, parameters) {
Parameters.Add(problem = new ValueParameter("Problem"));
Parameters.Add(bestSolution = new ValueParameter("BestFoundSolution"));
}
public LocalSolverContext(string name, string description) : base(name, description) {
Parameters.Add(problem = new ValueParameter("Problem"));
Parameters.Add(bestSolution = new ValueParameter("BestFoundSolution"));
}
public LocalSolverContext(string name, string description, ParameterCollection parameters) : base(name, description, parameters) {
Parameters.Add(problem = new ValueParameter("Problem"));
Parameters.Add(bestSolution = new ValueParameter("BestFoundSolution"));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new LocalSolverContext(this, cloner);
}
public ISingleObjectiveSolutionScope ToScope(GQAPSolution code, double fitness = double.NaN) {
var name = Problem.Encoding.Name;
var scope = new SingleObjectiveSolutionScope(code,
name + "Solution", fitness, Problem.Evaluator.QualityParameter.ActualName) {
Parent = Scope
};
scope.Variables.Add(new Variable(name, code.Assignment));
scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
return scope;
}
}
}