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 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Parameters;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LocalSolverNet {
|
---|
29 | [Item("LocalSolver Context", "A context for CPLEX solvers.")]
|
---|
30 | [StorableClass]
|
---|
31 | public class LocalSolverContext : SingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {
|
---|
32 |
|
---|
33 | [Storable]
|
---|
34 | private IValueParameter<GQAP> problem;
|
---|
35 | public GQAP Problem {
|
---|
36 | get { return problem.Value; }
|
---|
37 | set { problem.Value = value; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | [Storable]
|
---|
41 | private IValueParameter<GQAPSolution> bestSolution;
|
---|
42 | public GQAPSolution BestSolution {
|
---|
43 | get { return bestSolution.Value; }
|
---|
44 | set { bestSolution.Value = value; }
|
---|
45 | }
|
---|
46 |
|
---|
47 | [Storable]
|
---|
48 | private ValueParameter<DateTimeValue> lastUpdateTimeParameter;
|
---|
49 | public IValueParameter<DateTimeValue> LastUpdateTimeParameter {
|
---|
50 | get { return lastUpdateTimeParameter; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | [StorableConstructor]
|
---|
54 | protected LocalSolverContext(bool deserializing) : base(deserializing) { }
|
---|
55 | protected LocalSolverContext(LocalSolverContext original, Cloner cloner)
|
---|
56 | : base(original, cloner) {
|
---|
57 | problem = cloner.Clone(original.problem);
|
---|
58 | bestSolution = cloner.Clone(original.bestSolution);
|
---|
59 | lastUpdateTimeParameter = cloner.Clone(original.lastUpdateTimeParameter);
|
---|
60 | }
|
---|
61 | public LocalSolverContext() : base() {
|
---|
62 | Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
|
---|
63 | Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
|
---|
64 | Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));
|
---|
65 | }
|
---|
66 | public LocalSolverContext(string name) : base(name) {
|
---|
67 | Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
|
---|
68 | Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
|
---|
69 | Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));
|
---|
70 | }
|
---|
71 | public LocalSolverContext(string name, ParameterCollection parameters) : base(name, parameters) {
|
---|
72 | Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
|
---|
73 | Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
|
---|
74 | Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));
|
---|
75 | }
|
---|
76 | public LocalSolverContext(string name, string description) : base(name, description) {
|
---|
77 | Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
|
---|
78 | Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
|
---|
79 | Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));
|
---|
80 | }
|
---|
81 | public LocalSolverContext(string name, string description, ParameterCollection parameters) : base(name, description, parameters) {
|
---|
82 | Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
|
---|
83 | Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
|
---|
84 | Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));
|
---|
85 | }
|
---|
86 |
|
---|
87 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
88 | return new LocalSolverContext(this, cloner);
|
---|
89 | }
|
---|
90 |
|
---|
91 | public ISingleObjectiveSolutionScope<GQAPSolution> ToScope(GQAPSolution code, double fitness = double.NaN) {
|
---|
92 | var name = Problem.Encoding.Name;
|
---|
93 | var scope = new SingleObjectiveSolutionScope<GQAPSolution>(code,
|
---|
94 | name + "Solution", fitness, Problem.Evaluator.QualityParameter.ActualName) {
|
---|
95 | Parent = Scope
|
---|
96 | };
|
---|
97 | scope.Variables.Add(new Variable(name, code.Assignment));
|
---|
98 | scope.Variables.Add(new Variable("Evaluation", code.Evaluation));
|
---|
99 | return scope;
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|