Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/31/18 14:01:55 (7 years ago)
Author:
abeham
Message:

#1614: Added random search and fixed execution time counting for commercial solvers

Location:
branches/1614_GeneralizedQAP
Files:
1 added
6 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/1614_GeneralizedQAP/HeuristicLab.Algorithms.GRASP/3.3/HeuristicLab.Algorithms.GRASP-3.3.csproj

    r15688 r15698  
    108108      <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project>
    109109      <Name>HeuristicLab.Optimization-3.3</Name>
    110       <Private>False</Private>
    111110    </ProjectReference>
    112111  </ItemGroup>
  • branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/CPLEX/CplexSolver.cs

    r15634 r15698  
    2828using HeuristicLab.Encodings.IntegerVectorEncoding;
    2929using HeuristicLab.Optimization;
     30using HeuristicLab.Parameters;
    3031using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3132using ILOG.CPLEX;
     
    4950    }
    5051
     52    [Storable]
     53    private ValueParameter<DateTimeValue> lastUpdateTimeParameter;
     54    public IValueParameter<DateTimeValue> LastUpdateTimeParameter {
     55      get { return lastUpdateTimeParameter; }
     56    }
     57
    5158    [StorableConstructor]
    5259    protected CplexSolver(bool deserializing) : base(deserializing) { }
    5360    protected CplexSolver(CplexSolver original, Cloner cloner)
    5461    : base(original, cloner) {
     62      lastUpdateTimeParameter = cloner.Clone(original.lastUpdateTimeParameter);
    5563    }
    5664    public CplexSolver() {
    5765      Problem = new GQAP();
    58       ((MultiAnalyzer)Analyzer).AddOperator(new QualityPerClockAnalyzer());
     66      Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime", "") { Hidden = true });
     67      var qpc = new QualityPerClockAnalyzer();
     68      qpc.LastUpdateTimeParameter.ActualName = LastUpdateTimeParameter.Name;
     69      ((MultiAnalyzer)Analyzer).AddOperator(qpc);
    5970    }
    6071
     
    6980        opl.AddDataSource(dataSource);
    7081        opl.Generate();
     82        LastUpdateTimeParameter.Value = new DateTimeValue(DateTime.UtcNow);
    7183        cplex.Solve();
    7284        cplex.End();
  • branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms-3.3.csproj

    r15688 r15698  
    142142    <Compile Include="Properties\AssemblyInfo.cs" />
    143143    <Compile Include="Infrastructure\SingleObjectiveSolutionScope.cs" />
     144    <Compile Include="RandomSearch\RandomSearchContext.cs" />
     145    <Compile Include="RandomSearch\RandomSearch.cs" />
    144146  </ItemGroup>
    145147  <ItemGroup>
  • branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LocalSolverNet/GQAPBinarySolver.cs

    r15633 r15698  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Threading;
     25using HeuristicLab.Analysis;
    2426using HeuristicLab.Common;
    2527using HeuristicLab.Core;
     
    124126
    125127    protected override void Run(CancellationToken cancellationToken) {
     128      var qpc = ((MultiAnalyzer)Analyzer).Operators.OfType<QualityPerClockAnalyzer>().FirstOrDefault();
     129      if (qpc != null) {
     130        qpc.LastUpdateTimeParameter.ActualName = Context.LastUpdateTimeParameter.Name;
     131      }
    126132      token = cancellationToken;
    127133      lastUpdate = DateTime.UtcNow.AddSeconds(-1);
     
    205211        localSolver.AddCallback(LSCallbackType.IterationTicked, LocalSolverOnIterationTicked);
    206212
     213        Context.LastUpdateTimeParameter.Value = new DateTimeValue(DateTime.UtcNow);
     214
    207215        localSolver.Solve();
    208216
  • branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LocalSolverNet/GQAPIntegerSolver.cs

    r15633 r15698  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Threading;
     25using HeuristicLab.Analysis;
    2426using HeuristicLab.Common;
    2527using HeuristicLab.Core;
     
    118120
    119121    protected override void Run(CancellationToken cancellationToken) {
     122      var qpc = ((MultiAnalyzer)Analyzer).Operators.OfType<QualityPerClockAnalyzer>().FirstOrDefault();
     123      if (qpc != null) {
     124        qpc.LastUpdateTimeParameter.ActualName = Context.LastUpdateTimeParameter.Name;
     125      }
    120126      token = cancellationToken;
    121127      lastUpdate = DateTime.UtcNow.AddSeconds(-1);
     
    177183        localSolver.AddCallback(LSCallbackType.IterationTicked, LocalSolverOnIterationTicked);
    178184
     185        Context.LastUpdateTimeParameter.Value = new DateTimeValue(DateTime.UtcNow);
     186
    179187        localSolver.Solve();
    180188      } finally {
  • branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LocalSolverNet/LocalSolverContext.cs

    r15616 r15698  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    4445    }
    4546
     47    [Storable]
     48    private ValueParameter<DateTimeValue> lastUpdateTimeParameter;
     49    public IValueParameter<DateTimeValue> LastUpdateTimeParameter {
     50      get { return lastUpdateTimeParameter; }
     51    }
     52
    4653    [StorableConstructor]
    4754    protected LocalSolverContext(bool deserializing) : base(deserializing) { }
     
    5057      problem = cloner.Clone(original.problem);
    5158      bestSolution = cloner.Clone(original.bestSolution);
     59      lastUpdateTimeParameter = cloner.Clone(original.lastUpdateTimeParameter);
    5260    }
    5361    public LocalSolverContext() : base() {
    5462      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
    5563      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
     64      Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));
    5665    }
    5766    public LocalSolverContext(string name) : base(name) {
    5867      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
    5968      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
     69      Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));
    6070    }
    6171    public LocalSolverContext(string name, ParameterCollection parameters) : base(name, parameters) {
    6272      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
    6373      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
     74      Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));
    6475    }
    6576    public LocalSolverContext(string name, string description) : base(name, description) {
    6677      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
    6778      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
     79      Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));
    6880    }
    6981    public LocalSolverContext(string name, string description, ParameterCollection parameters) : base(name, description, parameters) {
    7082      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
    7183      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
     84      Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));
    7285    }
    7386   
  • branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/RandomSearch/RandomSearch.cs

    r15687 r15698  
    3030
    3131namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LocalSearch {
    32   [Item("Multi-start Local Search (GQAP)", "Multi-start local search for the GQAP.")]
     32  [Item("Random Search (GQAP)", "Random search for the GQAP.")]
    3333  [Creatable(CreatableAttribute.Categories.SingleSolutionAlgorithms)]
    3434  [StorableClass]
    35   public sealed class MultistartLS : StochasticAlgorithm<LocalSearchContext, IntegerVectorEncoding> {
     35  public sealed class RandomSearch : StochasticAlgorithm<LocalSearchContext, IntegerVectorEncoding> {
    3636
    3737    public override bool SupportsPause {
     
    4949
    5050    [StorableConstructor]
    51     private MultistartLS(bool deserializing) : base(deserializing) { }
    52     private MultistartLS(MultistartLS original, Cloner cloner)
     51    private RandomSearch(bool deserializing) : base(deserializing) { }
     52    private RandomSearch(RandomSearch original, Cloner cloner)
    5353      : base(original, cloner) {
    5454    }
    55     public MultistartLS() {
     55    public RandomSearch() {
    5656
    5757      Problem = new GQAP();
     
    5959   
    6060    public override IDeepCloneable Clone(Cloner cloner) {
    61       return new MultistartLS(this, cloner);
     61      return new RandomSearch(this, cloner);
    6262    }
    6363
     
    7474
    7575      while (!StoppingCriterion()) {
    76         var lsevaluations = 0;
    7776        var assign = new IntegerVector(Problem.ProblemInstance.Demands.Length, Context.Random, 0, Problem.ProblemInstance.Capacities.Length);
    7877        var eval = Problem.ProblemInstance.Evaluate(assign);
     78        var candidate = new GQAPSolution(assign, eval);
    7979        Context.EvaluatedSolutions++;
    80 
    81         var candidate = new GQAPSolution(assign, eval);
    82         OneOptLocalSearch.Apply(Context.Random, candidate, Problem.ProblemInstance, out lsevaluations);
    83         Context.EvaluatedSolutions += lsevaluations;
    8480
    8581        var candidateFit = Problem.ProblemInstance.ToSingleObjective(candidate.Evaluation);
  • branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/RandomSearch/RandomSearchContext.cs

    r15687 r15698  
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2626
    27 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LocalSearch {
    28   [Item("Local Search Context", "Context for local search algorithms.")]
     27namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.RandomSearch {
     28  [Item("Random Search Context", "Context for random search algorithms.")]
    2929  [StorableClass]
    30   public sealed class LocalSearchContext : SingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {
     30  public sealed class RandomSearchContext : SingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {
    3131    [Storable]
    3232    private IValueParameter<GQAP> problem;
     
    4444   
    4545    [StorableConstructor]
    46     private LocalSearchContext(bool deserializing) : base(deserializing) { }
    47     private LocalSearchContext(LocalSearchContext original, Cloner cloner)
     46    private RandomSearchContext(bool deserializing) : base(deserializing) { }
     47    private RandomSearchContext(RandomSearchContext original, Cloner cloner)
    4848    : base(original, cloner) {
    4949      problem = cloner.Clone(original.problem);
    5050      bestSolution = cloner.Clone(original.bestSolution);
    5151    }
    52     public LocalSearchContext() {
     52    public RandomSearchContext() {
    5353      Parameters.Add(problem = new ValueParameter<GQAP>("Problem"));
    5454      Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution"));
     
    5656
    5757    public override IDeepCloneable Clone(Cloner cloner) {
    58       return new LocalSearchContext(this, cloner);
     58      return new RandomSearchContext(this, cloner);
    5959    }
    6060
Note: See TracChangeset for help on using the changeset viewer.