Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/03/14 01:15:46 (9 years ago)
Author:
swagner
Message:

#2205: Worked on optimization networks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Nodes/KSPTSPConnector.cs

    r11519 r11520  
    2525using HeuristicLab.Encodings.BinaryVectorEncoding;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Problems.TravelingSalesman;
    2728using System.Linq;
    2829
     
    3334    [StorableConstructor]
    3435    protected KSPTSPConnector(bool deserializing) : base(deserializing) { }
    35     protected KSPTSPConnector(KSPTSPConnector original, Cloner cloner) : base(original, cloner) { }
     36    protected KSPTSPConnector(KSPTSPConnector original, Cloner cloner)
     37      : base(original, cloner) {
     38      RegisterEvents();
     39    }
    3640    public KSPTSPConnector()
    3741      : base("KSPTSPConnector") {
    3842      Initialize();
     43      RegisterEvents();
    3944    }
    4045    public KSPTSPConnector(string name)
    4146      : base(name) {
    4247      Initialize();
     48      RegisterEvents();
    4349    }
    4450    public KSPTSPConnector(string name, string description)
    4551      : base(name, description) {
    4652      Initialize();
     53      RegisterEvents();
     54    }
     55
     56    [StorableHook(HookType.AfterDeserialization)]
     57    private void AfterDeserialization() {
     58      RegisterEvents();
    4759    }
    4860
     
    6274      ksp.Parameters.Add(new PortParameter<DoubleValue>("Quality") { Type = PortParameterType.Input | PortParameterType.Output });
    6375      ksp.Parameters.Add(new PortParameter<DoubleValue>("TransportCosts") { Type = PortParameterType.Output });
    64       ksp.MessageReceived += Knapsack_MessageReceived;
     76      ksp.Parameters.Add(new PortParameter<PathTSPTour>("Route") { Type = PortParameterType.Output });
    6577
    6678      var tsp = new GenericPort("TSP Connector");
    6779      Ports.Add(tsp);
    6880      tsp.Parameters.Add(new PortParameter<DoubleMatrix>("Coordinates") { Type = PortParameterType.Output });
    69       ksp.Parameters.Add(new PortParameter<DoubleValue>("BestQuality") { Type = PortParameterType.Input });
     81      tsp.Parameters.Add(new PortParameter<PathTSPTour>("Best TSP Solution") { Type = PortParameterType.Input });
     82      tsp.Parameters.Add(new PortParameter<DoubleValue>("BestQuality") { Type = PortParameterType.Input });
     83    }
     84
     85    protected virtual void RegisterEvents() {
     86      var ksp = (IGenericPort)Ports["KSP Connector"];
     87      ksp.MessageReceived += Knapsack_MessageReceived;
    7088    }
    7189
     
    97115      tspMsg["Coordinates"] = coords;
    98116      tspConnectorPort.SendMessage(tspMsg, e.Value2);
     117      var tspSolution = (PathTSPTour)tspMsg["Best TSP Solution"];
    99118      var tspQuality = ((DoubleValue)tspMsg["BestQuality"]).Value;
    100119
     
    102121      ((DoubleValue)kspMsg["Quality"]).Value = kspQuality - factor * tspQuality;
    103122      kspMsg["TransportCosts"] = new DoubleValue(factor * tspQuality);
     123      kspMsg["Route"] = tspSolution;
    104124    }
    105125  }
Note: See TracChangeset for help on using the changeset viewer.