Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6260


Ignore:
Timestamp:
05/24/11 09:47:24 (14 years ago)
Author:
jhelm
Message:

#1329: Implemented PermutationWithRepetition Encoding. Implemented new operators for JSM Encoding.

Location:
branches/Scheduling
Files:
20 added
9 deleted
35 edited

Legend:

Unmodified
Added
Removed
  • branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/GanttChart.Designer.cs

    r6177 r6260  
    5454      this.chart.TabIndex = 0;
    5555      this.chart.Text = "chart";
     56      this.chart.MouseClick += new System.Windows.Forms.MouseEventHandler(this.chart_MouseClick);
    5657      //
    5758      // GanttChart
  • branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/GanttChart.cs

    r6177 r6260  
    99  public partial class GanttChart : UserControl {
    1010
    11     private IDictionary<string, Color> categories = new Dictionary<string, Color>();
     11    private IDictionary<int, Color> jobColors = new SortedDictionary<int, Color>();
    1212    private IDictionary<string, int> rowNames = new Dictionary<string, int>();
     13   
    1314
    1415    public GanttChart() {
    1516      InitializeComponent();
     17      chart.Series[0].YValueType = ChartValueType.Double;
    1618    }
    1719
    18     public void AddCategory(string name, Color color) {
    19       if (!categories.ContainsKey(name)) {
    20         categories[name] = color;
    21         chart.Legends[0].CustomItems.Add(color, name);
     20    public void AddJobColor(int jobNr) {
     21      if (!jobColors.ContainsKey(jobNr)) {
     22        Random r = new Random(jobNr + 1);
     23        jobColors[jobNr] = Color.FromArgb (r.Next(256),r.Next(256),r.Next(256));
     24        chart.Legends[0].CustomItems.Clear();
     25        if (jobColors.Count > 1) {
     26          int i = 0;
     27          foreach (Color c in jobColors.Values) {
     28            chart.Legends[0].CustomItems.Add(c, "Job#" + (i++));
     29          }
     30        }   
    2231      }
    23     }
    24 
    25     public void AddData(string rowName, string category, double start, double end, string tooltip, bool showLabel = true) {
    26       AddRowName(rowName);
    27       var point = CreateDataPoint(rowNames[rowName], rowName, start, end, showLabel ? category : string.Empty, categories[category]);
    28       point.ToolTip = tooltip;
    29       chart.Series[0].Points.Add(point);
    3032    }
    3133
     
    3739    }
    3840
    39     private static DataPoint CreateDataPoint(double x, string axisLabel, double start, double end, string text, Color color) {
    40       var point = new DataPoint(x, new double[] { start, end });
    41       point.Color = color;
    42       point.Label = text;
    43       point.AxisLabel = axisLabel;
    44       return point;
     41    public void AddData(string rowName, int jobNr, double start, double end, string tooltip, bool showLabel = true) {
     42      AddRowName(rowName);
     43      var point = new DataPoint(rowNames[rowName], new double[] { start, end });
     44      point.Color = jobColors[jobNr];
     45      point.AxisLabel = rowName;
     46      point.ToolTip = tooltip;
     47      chart.Series[0].Points.Add(point);
    4548    }
    4649
    4750    public void Reset() {
    4851      chart.Series[0].Points.Clear();
    49       categories.Clear();
     52      jobColors.Clear();
    5053      chart.Legends[0].CustomItems.Clear();
    5154      rowNames.Clear();
    5255    }
     56
     57    void chart_MouseClick(object sender, MouseEventArgs e) {
     58      var pos = e.Location;
     59      var results = chart.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint);
     60      foreach (DataPoint dp in chart.Series[0].Points) {
     61        Color newColor = Color.FromArgb(255, dp.Color);
     62        dp.Color = newColor;
     63      }
     64      foreach (var result in results) {
     65        if (result.ChartElementType == ChartElementType.DataPoint) {
     66          Color currentColor = chart.Series[0].Points[result.PointIndex].Color;
     67          foreach (DataPoint dp in result.Series.Points) {
     68            if (dp.Color != currentColor) {
     69              Color newColor = Color.FromArgb(0, dp.Color);
     70              dp.Color = newColor;
     71            }
     72          }
     73        }
     74      }
     75    }
    5376  }
    5477}
  • branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/HeuristicLab.Problems.Scheduling.Views-3.3.csproj

    r6177 r6260  
    3232  </PropertyGroup>
    3333  <ItemGroup>
     34    <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4">
     35      <HintPath>..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\bin\Debug\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath>
     36    </Reference>
     37    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4">
     38      <HintPath>..\..\HeuristicLab.Problems.DataAnalysis\3.4\bin\Debug\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
     39    </Reference>
     40    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4">
     41      <HintPath>..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\bin\Debug\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll</HintPath>
     42    </Reference>
     43    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4">
     44      <HintPath>..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression\3.4\bin\Debug\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.dll</HintPath>
     45    </Reference>
     46    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4">
     47      <HintPath>..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.Views\3.4\bin\Debug\HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.dll</HintPath>
     48    </Reference>
     49    <Reference Include="HeuristicLab.Problems.DataAnalysis.Views-3.4">
     50      <HintPath>..\..\HeuristicLab.Problems.DataAnalysis.Views\3.4\bin\Debug\HeuristicLab.Problems.DataAnalysis.Views-3.4.dll</HintPath>
     51    </Reference>
    3452    <Reference Include="System" />
    3553    <Reference Include="System.Core" />
     
    153171      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
    154172    </ProjectReference>
     173    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views-3.4.csproj">
     174      <Project>{20831A74-D18F-42D9-A667-1CE3AF53DF93}</Project>
     175      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views-3.4</Name>
     176    </ProjectReference>
    155177    <ProjectReference Include="..\..\HeuristicLab.Problems.Scheduling\3.3\HeuristicLab.Problems.Scheduling-3.3.csproj">
    156178      <Project>{2BF1D639-1A74-44ED-AAAD-41ECD395AD93}</Project>
  • branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/JobShopSchedulingProblemView.Designer.cs

    r6177 r6260  
    109109      // ganttChart
    110110      //
     111      this.ganttChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     112                  | System.Windows.Forms.AnchorStyles.Left)
     113                  | System.Windows.Forms.AnchorStyles.Right)));
    111114      this.ganttChart.Location = new System.Drawing.Point(0, 3);
    112115      this.ganttChart.Name = "ganttChart";
  • branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/JobShopSchedulingProblemView.cs

    r6177 r6260  
    5757    private void FillGanttChart(JobShopSchedulingProblem content) {
    5858      //Add Jobs as Categories
     59      ganttChart.Reset();
    5960      int jobCount = 0;
    60       Random random = new Random();
     61      Random random = new Random(1);
    6162      foreach (JSSPJob j in content.Jobs) {
    6263        foreach (JSSPTask t in content.Jobs[jobCount].Tasks) {
    63           string categoryName = "ScheduleTasks";
    64           categoryName = "Job" + t.Job.Index;
    65           ganttChart.AddCategory(categoryName, Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)));
     64          int categoryNr = t.JobNr.Value;
     65          string categoryName = "Job" + categoryNr;
     66          ganttChart.AddJobColor(categoryNr);
    6667          ganttChart.AddData(categoryName,
    67             categoryName,
     68            categoryNr,
    6869            t.StartTime.Value,
    6970            t.EndTime.Value,
    70             "Job" + t.Job.Index + " - " + "Task#" + t.TaskNr.Value.ToString(),
    71             false);
     71            "Job" + t.JobNr + " - " + "Task#" + t.TaskNr.Value.ToString());
    7272        }
    7373        jobCount++;
     
    9292          }
    9393
    94           /* TODO: Implement solution-import in problem-class
     94
    9595          if (!string.IsNullOrEmpty(spImportDialog.OptimalScheduleFileName))
    96             Content.ImportSolution(spImportDialog.OptimalScheduleFileName);
    97            * */
     96            Content.ImportJSMSolution(spImportDialog.OptimalScheduleFileName);
    9897          OnContentChanged();
    9998        }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/Plugin.cs

    r6177 r6260  
    2323
    2424namespace HeuristicLab.Problems.Scheduling.Views {
    25   [Plugin("HeuristicLab.Problems.Scheduling.Views", "3.3.3.6121")]
     25  [Plugin("HeuristicLab.Problems.Scheduling.Views", "3.3.3.6177")]
    2626  [PluginFile("HeuristicLab.Problems.Scheduling.Views-3.3.dll", PluginFileType.Assembly)]
    2727  public class HeuristicLabProblemsSchedulingViewsPlugin : PluginBase {
  • branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/Properties/AssemblyInfo.cs

    r6177 r6260  
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.3.0.0")]
    55 [assembly: AssemblyFileVersion("3.3.0.6121")]
     55[assembly: AssemblyFileVersion("3.3.0.6177")]
  • branches/Scheduling/HeuristicLab.Problems.Scheduling.Views/3.3/ScheduleView.cs

    r6177 r6260  
    4040    }
    4141
     42
     43    protected override void DeregisterContentEvents() {
     44      Content.QualityChanged -= new EventHandler(Content_QualityChanged);
     45      Content.ResourcesChanged -= new EventHandler(Content_ResourcesChanged);
     46
     47      base.DeregisterContentEvents();
     48    }
     49    protected override void RegisterContentEvents() {
     50      base.RegisterContentEvents();
     51      Content.QualityChanged += new EventHandler(Content_QualityChanged);
     52      Content.ResourcesChanged += new EventHandler(Content_ResourcesChanged);
     53    }
     54
     55
    4256    public new Schedule Content {
    4357      get { return (Schedule)base.Content; }
     
    5973
    6074    private void FillGanttChart(Schedule content) {
    61       //Add Resources as Categories
     75      ResetGanttChart();
    6276      int resCount = 0;
    63       Random random = new Random ();
     77      Random random = new Random (1);
    6478      foreach (Resource r in content.Resources) {
    6579        foreach (JSSPTask t in content.Resources[resCount].Tasks) {
     80          int categoryNr = 0;     
     81          string toolTip = "Task#" + t.TaskNr;
    6682          string categoryName = "ScheduleTasks";
    67           string toolTip = "Task#" + t.TaskNr.Value.ToString();
    6883          if (t is JSSPTask) {
    69             categoryName = "Job" + ((JSSPTask)t).Job.Index;
     84            categoryNr = ((JSSPTask)t).JobNr.Value;
     85            categoryName = "Job" + categoryNr;
    7086            toolTip = categoryName + " - " + toolTip;
    71           }
    72           ganttChart.AddCategory(categoryName, Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)));
     87          } 
     88          ganttChart.AddJobColor(categoryNr);
    7389          ganttChart.AddData("Resource" + r.Index,
    74             categoryName,
     90            categoryNr,
    7591            t.StartTime.Value,
    7692            t.EndTime.Value,
    77             toolTip,
    78             false);
     93            toolTip);
    7994        }
    8095        resCount++;
     
    86101      ganttChart.Enabled = Content != null;
    87102    }
     103
     104
     105    private void Content_QualityChanged(object sender, EventArgs e) {
     106      if (InvokeRequired)
     107        Invoke(new EventHandler(Content_QualityChanged), sender, e);
     108      else {
     109        if (Content == null) {
     110          ResetGanttChart();
     111        } else {
     112          FillGanttChart(Content);
     113        }
     114      }
     115    }
     116
     117    private void Content_ResourcesChanged(object sender, EventArgs e) {
     118      if (InvokeRequired)
     119        Invoke(new EventHandler(Content_ResourcesChanged), sender, e);
     120      else {
     121        if (Content == null) {
     122          ResetGanttChart();
     123        } else {
     124          FillGanttChart(Content);
     125        }
     126      }
     127    }
    88128  }
    89129}
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Analyzers/BestSchedulingSolutionAnalyzer.cs

    r6177 r6260  
    121121        if (max && bestSolution.Quality.Value < qualities[i].Value ||
    122122          !max && bestSolution.Quality.Value > qualities[i].Value) {
    123             bestSolution = (Schedule)solutions[i].Clone();
    124123          bestSolution.Quality.Value = qualities[i].Value;
     124          bestSolution.Resources = (ItemList<Resource>)solutions[i].Resources.Clone();
    125125        }
    126126      }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JSSPCreator.cs

    r6177 r6260  
    3434  [Item("JobShop Scheduling Problem Creator", "Represents the generalized form of creators for JobShop Scheduling Problems.")]
    3535  [StorableClass]
    36   public abstract class JSSPCreator<T> :JSSPOperator, IJSSPCreator where T : Item, IJSSPEncoding{
     36  public abstract class JSSPCreator<T> :JSSPOperator, ISchedulingCreator where T : Item, ISchedulingEncoding{
    3737    [StorableConstructor]
    3838    protected JSSPCreator(bool deserializing) : base(deserializing) { }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JSSPCrossover.cs

    r6177 r6260  
    3030  [Item("JSSPCrossover", "A scheduling crossover operation.")]
    3131  [StorableClass]
    32   public abstract class JSSPCrossover : JSSPOperator, IJSSPCrossover, IStochasticOperator {
     32  public abstract class JSSPCrossover<T> : JSSPOperator, ISchedulingCrossover, IStochasticOperator where T : Item, ISchedulingEncoding {
    3333    #region IJSSPCrossover Members
    34     public ILookupParameter<ItemArray<IJSSPEncoding>> ParentsParameter {
    35       get { return (ScopeTreeLookupParameter<IJSSPEncoding>)Parameters["Parents"]; }
     34    public ILookupParameter<ItemArray<T>> ParentsParameter {
     35      get { return (ScopeTreeLookupParameter<T>)Parameters["Parents"]; }
    3636    }
    3737
    38     public ILookupParameter<IJSSPEncoding> ChildParameter {
    39       get { return (ILookupParameter<IJSSPEncoding>)Parameters["Child"]; }
     38    public ILookupParameter<T> ChildParameter {
     39      get { return (ILookupParameter<T>)Parameters["Child"]; }
    4040    }
    4141    #endregion
     
    4747    [StorableConstructor]
    4848    protected JSSPCrossover(bool deserializing) : base(deserializing) { }
    49     protected JSSPCrossover(JSSPCrossover original, Cloner cloner)
     49    protected JSSPCrossover(JSSPCrossover<T> original, Cloner cloner)
    5050      : base(original, cloner) {
    5151    }
     
    5353      : base() {
    5454        Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    55       Parameters.Add(new ScopeTreeLookupParameter<IJSSPEncoding>("Parents", "The parent solution which should be crossed."));
     55      Parameters.Add(new ScopeTreeLookupParameter<T>("Parents", "The parent solution which should be crossed."));
    5656      ParentsParameter.ActualName = "SchedulingSolution";
    57       Parameters.Add(new LookupParameter<IJSSPEncoding>("Child", "The child solution resulting from the crossover."));
     57      Parameters.Add(new LookupParameter<T>("Child", "The child solution resulting from the crossover."));
    5858      ChildParameter.ActualName = "SchedulingSolution";
    5959    }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JSSPDecoder.cs

    r6177 r6260  
    3131
    3232namespace HeuristicLab.Problems.Scheduling.Encodings {
    33   public abstract class JSSPDecoder<T> : JSSPOperator, IJSSPDecoder where T : Item, IJSSPEncoding {
     33  public abstract class JSSPDecoder<T> : JSSPOperator, ISchedulingDecoder where T : Item, ISchedulingEncoding {
    3434    [StorableConstructor]
    3535    protected JSSPDecoder(bool deserializing) : base(deserializing) { }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JSSPEncodingTypes.cs

    r6177 r6260  
    77  public enum JSSPEncodingTypes {
    88    JSMEncoding,
    9     PRVEncoding
     9    PRVEncoding,
     10    PWREncoding
    1011  }
    1112}
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JSSPManipulator.cs

    r6177 r6260  
    3030  [Item("JSSPManipulator", "A JSSP manipulation operation.")]
    3131  [StorableClass]
    32   public abstract class JSSPManipulator : JSSPOperator, IJSSPManipulator, IStochasticOperator {
     32  public abstract class JSSPManipulator<T> : JSSPOperator, ISchedulingManipulator, IStochasticOperator where T : Item, ISchedulingEncoding {
    3333    #region IJSSPManipulator Members
    3434
    35     public ILookupParameter<IJSSPEncoding> SchedulingSolutionParameter {
    36       get { return (ILookupParameter<IJSSPEncoding>)Parameters["SchedulingSolution"]; }
     35    public ILookupParameter<T> SchedulingSolutionParameter {
     36      get { return (ILookupParameter<T>)Parameters["SchedulingSolution"]; }
    3737    }
    3838
     
    4545    [StorableConstructor]
    4646    protected JSSPManipulator(bool deserializing) : base(deserializing) { }
    47     protected JSSPManipulator(JSSPManipulator original, Cloner cloner)
     47    protected JSSPManipulator(JSSPManipulator<T> original, Cloner cloner)
    4848      : base(original, cloner) {
    4949    }
    5050    public JSSPManipulator()
    5151      : base() {
    52         Parameters.Add(new LookupParameter<IJSSPEncoding>("SchedulingSolution", "The JSSP solution to be manipulated."));
     52        Parameters.Add(new LookupParameter<T>("SchedulingSolution", "The JSSP solution to be manipulated."));
    5353        Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    5454    }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JSSPOperator.cs

    r6177 r6260  
    3535  [Item("SchedulingOperator", "A scheduling operator.")]
    3636  [StorableClass]
    37   public abstract class JSSPOperator : SingleSuccessorOperator, IJSSPOperator{
     37  public abstract class JSSPOperator : SingleSuccessorOperator, ISchedulingOperator{
    3838    [StorableConstructor]
    3939    protected JSSPOperator(bool deserializing) : base(deserializing) { }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Crossovers/JSMCrossover.cs

    r6177 r6260  
    3030  [Item("JSMCrossover", "An operator which crosses two JSM representations.")]
    3131  [StorableClass]
    32   public abstract class JSMCrossover : JSSPCrossover, IJSMOperator {
     32  public abstract class JSMCrossover : JSSPCrossover<JSMEncoding>, IJSMOperator {
    3333
    3434    [StorableConstructor]
     
    3939    }
    4040
    41     public abstract IJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2);
     41    public abstract JSMEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2);
    4242
    4343    public override IOperation Apply() {
    44       ItemArray<IJSSPEncoding> parents = ParentsParameter.ActualValue;
     44      ItemArray<JSMEncoding> parents = ParentsParameter.ActualValue;
    4545
    4646      ChildParameter.ActualValue =
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Crossovers/JSMJOXCrossover.cs

    r6177 r6260  
    4646    public JSMJOXCrossover() : base() { }
    4747
    48     public static IJSSPEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
     48    public static JSMEncoding Cross(IRandom random, JSMEncoding p1, JSMEncoding p2) {
    4949      JSMEncoding result = new JSMEncoding();
    5050
    51       int nrOfResources = parent1.JobSequenceMatrix.Count;
    52       int nrOfJobs = parent1.JobSequenceMatrix[0].Length;
     51      int nrOfResources = p1.JobSequenceMatrix.Count;
     52      int nrOfJobs = p1.JobSequenceMatrix[0].Length;
    5353
    5454      //Determine randomly which jobindexes persist
     
    5656      for (int i = 0; i < persist.Length; i++) {
    5757        persist[i] = random.Next(2) == 1;
    58       }
     58      }   
     59
     60      bool dominantParent = random.Next(2) == 1;
     61      JSMEncoding parent1 = dominantParent ? p1 : p2;
     62      JSMEncoding parent2 = dominantParent ? p2 : p1;
    5963
    6064      //Fill childmatrix with values
     
    7781    }
    7882
    79     public override IJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
     83    public override JSMEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
    8084      return Cross(random, parent1, parent2);
    8185    }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Crossovers/JSMSXXCrossover.cs

    r6177 r6260  
    4545    public JSMSXXCrossover () : base () {}
    4646
    47     public static IJSSPEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
     47    public static JSMEncoding Cross(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
    4848      JSMEncoding result = new JSMEncoding();
    4949
    50       int subSequenceLength = 3;
     50      int subSequenceLength = random.Next (parent1.JobSequenceMatrix[0].Length);
    5151
    5252      for (int i = 0; i < parent1.JobSequenceMatrix.Count; i++) {
     
    102102
    103103
    104     public override IJSSPEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
     104    public override JSMEncoding Crossover(IRandom random, JSMEncoding parent1, JSMEncoding parent2) {
    105105      return Cross(random, parent1, parent2);
    106106    }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/JSMDecoder.cs

    r6177 r6260  
    4141      : base(original, cloner) {
    4242        this.resultingSchedule = cloner.Clone(original.resultingSchedule);
     43        this.jobs = cloner.Clone(original.jobs);
    4344        this.decodingErrorPolicy = original.decodingErrorPolicy;
    4445        this.forcingStrategy = original.forcingStrategy;
     
    5253    }
    5354
     55    #region Private Members
    5456    [Storable]
    5557    private Schedule resultingSchedule;
    5658
    5759    [Storable]
     60    private ItemList<JSSPJob> jobs;
     61
     62    [Storable]
    5863    private JSMDecodingErrorPolicyTypes decodingErrorPolicy = JSMDecodingErrorPolicyTypes.GuidedPolicy;
    5964
    6065    [Storable]
    61     private JSMForcingStrategyTypes forcingStrategy = JSMForcingStrategyTypes.ShiftForcing;
     66    private JSMForcingStrategyTypes forcingStrategy = JSMForcingStrategyTypes.ShiftForcing;
     67    #endregion
    6268
    6369    public JSMDecoder()
     
    6672    }
    6773
    68     private ItemList<JSSPTask> GetEarliestNotScheduledTasks(ItemList<JSSPJob> jobs) {
     74    private ItemList<JSSPTask> GetEarliestNotScheduledTasks() {
    6975      ItemList<JSSPTask> result = new ItemList<JSSPTask>();
    7076      foreach (JSSPJob j in jobs) {
     
    7985    }
    8086    private JSSPTask GetTaskWithMinimalEC(ItemList<JSSPTask> earliestTasksList) {
    81       DoubleValue minEct = new DoubleValue(Double.MaxValue);
     87      double minEct = double.MaxValue;
    8288      JSSPTask result = null;
    8389      foreach (JSSPTask t in earliestTasksList) {
    84         DoubleValue ect = ComputeEarliestCompletionTime(t);
    85         if (ect.Value < minEct.Value) {
     90        double ect = resultingSchedule.ComputeEarliestCompletionTime(t, jobs[t.JobNr.Value]);
     91        if (ect < minEct) {
    8692          result = t;
    8793          minEct = ect;
     
    9298    private ItemList<JSSPTask> GetConflictSetForTask(JSSPTask conflictedTask, ItemList<JSSPTask> earliestTasksList) {
    9399      ItemList<JSSPTask> result = new ItemList<JSSPTask>();
    94       DoubleValue conflictedCompletionTime = ComputeEarliestCompletionTime(conflictedTask);
     100      double conflictedCompletionTime = resultingSchedule.ComputeEarliestCompletionTime(conflictedTask, jobs[conflictedTask.JobNr.Value]);
    95101      result.Add(conflictedTask);
    96102      foreach (JSSPTask t in earliestTasksList) {
    97103        if (t.ResourceNr.Value == conflictedTask.ResourceNr.Value) {
    98           if (ComputeEarliestStartTime(t).Value < conflictedCompletionTime.Value)
     104          if (resultingSchedule.ComputeEarliestStartTime(t, jobs[t.JobNr.Value]) < conflictedCompletionTime)
    99105            result.Add(t);
    100106        }
     
    102108      return result;
    103109    }
    104     private JSSPTask SelectTaskFromConflictSet(IntValue conflictedResource, ItemList<JSSPTask> conflictSet, ItemList<Permutation> jsm) {
    105       JSSPTask result = null;
    106       IntValue progressOnResource = new IntValue (resultingSchedule.Resources[conflictedResource.Value].Tasks.Count);
    107 
    108       if (progressOnResource.Value < jsm[conflictedResource.Value].Length) {
    109         IntValue solutionCandidateJobNr = new IntValue(jsm[conflictedResource.Value][progressOnResource.Value]);
    110         foreach (JSSPTask t in conflictSet) {
    111           if (t.Job.Index.Value == solutionCandidateJobNr.Value)
    112             result = t;
    113         }
     110    private JSSPTask SelectTaskFromConflictSet(int conflictedResourceNr, int progressOnConflictedResource, ItemList<JSSPTask> conflictSet, ItemList<Permutation> jsm) {
     111      if (conflictSet.Count == 1)
     112        return conflictSet[0];
     113     
     114      //get solutionCandidate from jobSequencingMatrix
     115      int solutionCandidateJobNr = jsm[conflictedResourceNr][progressOnConflictedResource];
     116
     117      //scan conflictSet for given solutionCandidate, and return if found
     118      foreach (JSSPTask t in conflictSet) {
     119        if (t.JobNr.Value == solutionCandidateJobNr)
     120          return t;
     121      }
     122
     123      //if solutionCandidate wasn't found in conflictSet apply DecodingErrorPolicy and ForcingPolicy
     124      JSSPTask result = ApplyDecodingErrorPolicy(conflictSet, jsm[conflictedResourceNr], progressOnConflictedResource);
     125      int newResolutionIndex = 0;
     126
     127      while (newResolutionIndex < jsm[conflictedResourceNr].Length && jsm[conflictedResourceNr][newResolutionIndex] != result.JobNr.Value)
     128        newResolutionIndex++;
     129      ApplyForcingStrategy(jsm, conflictedResourceNr, newResolutionIndex, progressOnConflictedResource, result.JobNr.Value);
     130
     131      return result;
     132    }
     133    private JSSPTask ApplyDecodingErrorPolicy(ItemList<JSSPTask> conflictSet, Permutation resource, int progress) {
     134      if (decodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) {
     135        //Random
     136        return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)];
    114137      } else {
    115         return null;
    116       }
    117 
    118       //Repairing happens here
    119       if (result == null) {
    120         //Decoding Error Policy BEGIN
    121         //CHOOSE OTHER RESOLUTION FOR CONFLICT SET
    122         result = ApplyDecodingErrorPolicy(conflictSet);
    123         //result = conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)];
    124         //Decoding Error Policy END
    125 
    126 
    127         //Determine index of new resolution
    128         int index = 0;
    129         while (index < jsm[conflictedResource.Value].Length &&
    130           jsm[conflictedResource.Value][index] != result.Job.Index.Value)
    131           index++;
    132 
    133 
    134         //Forcing Strategy BEGIN
    135         ApplyForcingStrategy(jsm, conflictedResource.Value, index, progressOnResource.Value, result.Job.Index.Value);
    136        
    137         //ForcingStrategy END
    138       }
    139       return result;
    140     }
    141 
     138        //Guided
     139        for (int i = progress; i < resource.Length; i++) {
     140          int j = 0;
     141          while (j < conflictSet.Count && conflictSet[j].JobNr.Value != resource[i])
     142            j++;
     143
     144          if (j < conflictSet.Count)
     145            return (conflictSet[j]);
     146        }
     147        return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)];
     148      }   
     149    }
    142150    private void ApplyForcingStrategy(ItemList<Permutation> jsm, int conflictedResource, int newResolutionIndex, int progressOnResource, int newResolution) {
    143       //if (forcingStrategy == JSMForcingStrategyTypes.SwapForcing) {
     151      if (forcingStrategy == JSMForcingStrategyTypes.SwapForcing) {
    144152        //SwapForcing
    145153        jsm[conflictedResource][newResolutionIndex] = jsm[conflictedResource][progressOnResource];
    146154        jsm[conflictedResource][progressOnResource] = newResolution;
    147       /*} else {
     155      } else {
    148156        //ShiftForcing
    149 
    150       } */
    151     }
    152 
    153     private JSSPTask ApplyDecodingErrorPolicy(ItemList<JSSPTask> conflictSet) {
    154       //if (decodingErrorPolicy == JSMDecodingErrorPolicyTypes.RandomPolicy) {
    155         //Random
    156         return conflictSet[RandomParameter.ActualValue.Next(conflictSet.Count - 1)];
    157       /*} else {
    158         //Guided
    159 
    160       }    */
    161     }
    162     private DoubleValue ComputeEarliestStartTime(JSSPTask t) {
    163       Resource affectedResource = resultingSchedule.Resources[t.ResourceNr.Value];
    164 
    165       DoubleValue lastMachineEndTime = affectedResource.TotalDuration;
    166       DoubleValue previousJoboperationEndTime = new DoubleValue(double.MinValue);
    167       if (t.PreviousTask != null)
    168         previousJoboperationEndTime = t.PreviousTask.EndTime;
    169 
    170       return new DoubleValue(Math.Max(previousJoboperationEndTime.Value, lastMachineEndTime.Value));
    171     }
    172     private DoubleValue ComputeEarliestCompletionTime(JSSPTask t) {
    173       return new DoubleValue(ComputeEarliestStartTime(t).Value + t.Duration.Value);
    174     }
    175     private void AddTaskToSchedule(JSSPTask selectedTask) {
    176       Resource affectedResource = resultingSchedule.Resources[selectedTask.ResourceNr.Value];
    177       selectedTask.StartTime = ComputeEarliestStartTime(selectedTask);
    178       selectedTask.IsScheduled.Value = true;
    179       affectedResource.Tasks.Add(selectedTask);
    180     }
    181 
    182     public override Schedule CreateScheduleFromEncoding(JSMEncoding solution) {
     157        List<int> asList = jsm[conflictedResource].ToList<int>();
     158        if (newResolutionIndex > progressOnResource) {
     159          asList.RemoveAt(newResolutionIndex);
     160          asList.Insert(progressOnResource, newResolution);
     161        } else {
     162          asList.Insert(progressOnResource, newResolution);
     163          asList.RemoveAt(newResolutionIndex);
     164        }
     165        jsm[conflictedResource] = new Permutation (PermutationTypes.Absolute, asList.ToArray<int>());
     166      }
     167    }
     168
     169    public Schedule CreateScheduleFromEncoding(JSMEncoding solution, ItemList<JSSPJob> jobData) {
    183170      ItemList<Permutation> jobSequenceMatrix = solution.JobSequenceMatrix;
    184171
    185       resultingSchedule = new Schedule(new IntValue(Jobs[0].Tasks.Count));
     172      jobs = (ItemList<JSSPJob>)jobData.Clone();
     173      resultingSchedule = new Schedule(new IntValue(jobs[0].Tasks.Count));
    186174
    187175      //Reset scheduled tasks in result
    188       foreach (JSSPJob j in Jobs) {
     176      foreach (JSSPJob j in jobs) {
    189177        foreach (JSSPTask t in j.Tasks) {
    190178          t.IsScheduled.Value = false;
     
    194182      //GT-Algorithm
    195183      //STEP 0 - Compute a list of "earliest operations"
    196       ItemList<JSSPTask> earliestTasksList = GetEarliestNotScheduledTasks(Jobs);
     184      ItemList<JSSPTask> earliestTasksList = GetEarliestNotScheduledTasks();
    197185      while (earliestTasksList.Count > 0) {
    198186        //STEP 1 - Get earliest not scheduled operation with minimal earliest completing time
    199187        JSSPTask minimal = GetTaskWithMinimalEC(earliestTasksList);
    200 
    201         //STEP 2 - Compute a conflict set of all operations that can be scheduled on the machine the previously selected operation runs on
     188        int conflictedResourceNr = minimal.ResourceNr.Value;
     189        Resource conflictedResource = resultingSchedule.Resources[conflictedResourceNr];
     190
     191        //STEP 2 - Compute a conflict set of all operations that can be scheduled on the conflicted resource
    202192        ItemList<JSSPTask> conflictSet = GetConflictSetForTask(minimal, earliestTasksList);
    203193
    204         //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..)
    205         JSSPTask selectedTask = SelectTaskFromConflictSet(minimal.ResourceNr, conflictSet, jobSequenceMatrix);
    206 
    207         //STEP 4 - Adding the selected operation to the current schedule
    208         AddTaskToSchedule(selectedTask);
     194        //STEP 3 - Select a task from the conflict set
     195        int progressOnResource = conflictedResource.Tasks.Count;
     196        JSSPTask selectedTask = SelectTaskFromConflictSet(conflictedResourceNr, progressOnResource, conflictSet, jobSequenceMatrix);
     197
     198        //STEP 4 - Add the selected task to the current schedule
     199        selectedTask.IsScheduled.Value = true;
     200        resultingSchedule.AddTask(selectedTask, jobs[selectedTask.JobNr.Value]);
    209201
    210202        //STEP 5 - Back to STEP 1
    211         earliestTasksList = GetEarliestNotScheduledTasks(Jobs);
     203        earliestTasksList = GetEarliestNotScheduledTasks();
    212204      }
    213205
    214206      return resultingSchedule;
     207    }
     208
     209    public override Schedule CreateScheduleFromEncoding(JSMEncoding solution) {
     210      return CreateScheduleFromEncoding(solution, Jobs);
    215211    }
    216212
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/JSMEncoding.cs

    r6177 r6260  
    3636  [Item("Job Sequencing Matrix Encoding", "Represents a solution for a standard JobShop Scheduling Problem.")]
    3737  [StorableClass]
    38   public class JSMEncoding : ParameterizedNamedItem, IJSSPEncoding{
     38  public class JSMEncoding : ParameterizedNamedItem, ISchedulingEncoding{
    3939    [StorableConstructor]
    4040    protected JSMEncoding(bool deserializing) : base(deserializing) { }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/JobSequenceMatrix/Manipulators/JSMManipulator.cs

    r6177 r6260  
    3232  [Item("AlbaManipulator", "An operator which manipulates a VRP representation.")]
    3333  [StorableClass]
    34   public abstract class JSMManipulator : JSSPManipulator, IJSMOperator {
     34  public abstract class JSMManipulator : JSSPManipulator<JSMEncoding>, IJSMOperator {
    3535    [StorableConstructor]
    3636    protected JSMManipulator(bool deserializing) : base(deserializing) { }
     
    4444
    4545    public override IOperation Apply() {
    46       IJSSPEncoding solution = SchedulingSolutionParameter.ActualValue;
     46      JSMEncoding solution = SchedulingSolutionParameter.ActualValue;
    4747
    48       SchedulingSolutionParameter.ActualValue = Manipulate(RandomParameter.ActualValue, solution as JSMEncoding);
     48      int nrOfMutations = RandomParameter.ActualValue.Next(5) + 1;
     49
     50      for (int i = 0; i < nrOfMutations; i++ )
     51        SchedulingSolutionParameter.ActualValue = Manipulate(RandomParameter.ActualValue, solution as JSMEncoding);
    4952
    5053      return base.Apply();
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/PriorityRulesVector/Crossovers/PRVCrossover.cs

    r6177 r6260  
    2828
    2929namespace HeuristicLab.Problems.Scheduling.Encodings.PriorityRulesVector.Crossovers {
    30   [Item("JSMCrossover", "An operator which crosses two JSM representations.")]
     30  [Item("PRVCrossover", "An operator which crosses two PRV representations.")]
    3131  [StorableClass]
    32   public abstract class PRVCrossover : JSSPCrossover, IPRVOperator {
     32  public abstract class PRVCrossover : JSSPCrossover<PRVEncoding>, IPRVOperator {
    3333
    3434    [StorableConstructor]
     
    3939    }
    4040
    41     public abstract IJSSPEncoding Crossover(IRandom random, PRVEncoding parent1, PRVEncoding parent2);
     41    public abstract PRVEncoding Crossover(IRandom random, PRVEncoding parent1, PRVEncoding parent2);
    4242
    4343    public override IOperation Apply() {
    44       ItemArray<IJSSPEncoding> parents = ParentsParameter.ActualValue;
     44      ItemArray<PRVEncoding> parents = ParentsParameter.ActualValue;
    4545
    4646      ChildParameter.ActualValue =
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/PriorityRulesVector/Crossovers/PRVDiscreteCrossover.cs

    r6177 r6260  
    4545    public PRVDiscreteCrossover() : base() { }
    4646
    47     public static IJSSPEncoding Cross(IRandom random, PRVEncoding parent1, PRVEncoding parent2) {
     47    public static PRVEncoding Cross(IRandom random, PRVEncoding parent1, PRVEncoding parent2) {
    4848      return new PRVEncoding(DiscreteCrossover.Apply(random, parent1, parent2), parent1.NrOfRules);
    4949    }
    5050
    51     public override IJSSPEncoding Crossover(IRandom random, PRVEncoding parent1, PRVEncoding parent2) {
     51    public override PRVEncoding Crossover(IRandom random, PRVEncoding parent1, PRVEncoding parent2) {
    5252      return Cross(random, parent1, parent2);
    5353    }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/PriorityRulesVector/Crossovers/PRVSinglePointCrossover.cs

    r6177 r6260  
    4545    public PRVSinglePointCrossover() : base() { }
    4646
    47     public static IJSSPEncoding Cross(IRandom random, PRVEncoding parent1, PRVEncoding parent2) {
     47    public static PRVEncoding Cross(IRandom random, PRVEncoding parent1, PRVEncoding parent2) {
    4848      return new PRVEncoding(SinglePointCrossover.Apply(random, parent1, parent2), parent1.NrOfRules);
    4949    }
    5050
    51     public override IJSSPEncoding Crossover(IRandom random, PRVEncoding parent1, PRVEncoding parent2) {
    52       return Cross(random, parent1, parent2);
     51    public override PRVEncoding Crossover(IRandom random, PRVEncoding parent1, PRVEncoding parent2) {
     52      return Cross(random, parent1, parent2);;
    5353    }
    5454  }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/PriorityRulesVector/Manipulators/PRVManipulator.cs

    r6177 r6260  
    3030
    3131namespace HeuristicLab.Problems.Scheduling.Encodings.PriorityRulesVector.Manipulators {
    32   [Item("AlbaManipulator", "An operator which manipulates a VRP representation.")]
     32  [Item("PRVManipulator", "An operator which manipulates a PRV representation.")]
    3333  [StorableClass]
    34   public abstract class PRVManipulator : JSSPManipulator, IPRVOperator {
     34  public abstract class PRVManipulator : JSSPManipulator<PRVEncoding>, IPRVOperator {
    3535    [StorableConstructor]
    3636    protected PRVManipulator(bool deserializing) : base(deserializing) { }
     
    4444
    4545    public override IOperation Apply() {
    46       IJSSPEncoding solution = SchedulingSolutionParameter.ActualValue;
     46      PRVEncoding solution = SchedulingSolutionParameter.ActualValue;
    4747
    4848      SchedulingSolutionParameter.ActualValue = Manipulate(RandomParameter.ActualValue, solution as PRVEncoding);
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/PriorityRulesVector/PRVDecoder.cs

    r6177 r6260  
    5050    }
    5151
     52    #region Private Members
    5253    [Storable]
    5354    private Schedule resultingSchedule;
    5455
    55     public PRVDecoder()
    56       : base() {
    57       Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
    58     }
     56    [Storable]
     57    private ItemList<JSSPJob> jobs;
     58    #endregion
    5959
    6060    #region Priority Rules
     
    6767    //earliest start time
    6868    private JSSPTask ESTRule(ItemList<JSSPTask> tasks) {
    69       JSSPTask currentResult = tasks[0];
     69      JSSPTask currentResult = RandomRule(tasks);
    7070      double currentEST = double.MaxValue;
    7171      foreach (JSSPTask t in tasks) {
    72         double est = ComputeEarliestStartTime(t).Value;
     72        double est = resultingSchedule.ComputeEarliestStartTime(t, jobs[t.JobNr.Value]);
    7373        if (est < currentEST) {
    7474          currentEST = est;
     
    8181    //shortest processingtime
    8282    private JSSPTask SPTRule(ItemList<JSSPTask> tasks) {
    83       JSSPTask currentResult = tasks[0];
     83      JSSPTask currentResult = RandomRule(tasks);
    8484      foreach (JSSPTask t in tasks) {
    8585        if (t.Duration.Value < currentResult.Duration.Value)
     
    9191    //longest processing time   
    9292    private JSSPTask LPTRule(ItemList<JSSPTask> tasks) {
    93       JSSPTask currentResult = tasks[0];
     93      JSSPTask currentResult = RandomRule(tasks);
    9494      foreach (JSSPTask t in tasks) {
    9595        if (t.Duration.Value > currentResult.Duration.Value)
     
    101101    //most work remaining
    102102    private JSSPTask MWRRule(ItemList<JSSPTask> tasks) {
    103       JSSPTask currentResult = tasks[0];
     103      JSSPTask currentResult = RandomRule(tasks);
    104104      double currentLargestRemainingProcessingTime = 0;
    105105      foreach (JSSPTask t in tasks) {
    106106        double remainingProcessingTime = 0;
    107         foreach (JSSPTask jt in t.Job.Tasks) {
     107        foreach (JSSPTask jt in jobs[t.JobNr.Value].Tasks) {
    108108          if (!jt.IsScheduled.Value)
    109109            remainingProcessingTime += jt.Duration.Value;
     
    119119    //least work remaining
    120120    private JSSPTask LWRRule(ItemList<JSSPTask> tasks) {
    121       JSSPTask currentResult = tasks[0];
     121      JSSPTask currentResult = RandomRule(tasks);
    122122      double currentSmallestRemainingProcessingTime = double.MaxValue;
    123123      foreach (JSSPTask t in tasks) {
    124124        double remainingProcessingTime = 0;
    125         foreach (JSSPTask jt in t.Job.Tasks) {
     125        foreach (JSSPTask jt in jobs[t.JobNr.Value].Tasks) {
    126126          if (!jt.IsScheduled.Value)
    127127            remainingProcessingTime += jt.Duration.Value;
     
    137137    //most operations remaining
    138138    private JSSPTask MORRule(ItemList<JSSPTask> tasks) {
    139       JSSPTask currentResult = tasks[0];
     139      JSSPTask currentResult = RandomRule(tasks);
    140140      int currentLargestNrOfRemainingTasks = 0;
    141141      foreach (JSSPTask t in tasks) {
    142142        int nrOfRemainingTasks = 0;
    143         foreach (JSSPTask jt in t.Job.Tasks) {
     143        foreach (JSSPTask jt in jobs[t.JobNr.Value].Tasks) {
    144144          if (!jt.IsScheduled.Value)
    145145            nrOfRemainingTasks++;
     
    155155    //least operationsremaining
    156156    private JSSPTask LORRule(ItemList<JSSPTask> tasks) {
    157       JSSPTask currentResult = tasks[0];
     157      JSSPTask currentResult = RandomRule(tasks);
    158158      int currentSmallestNrOfRemainingTasks = int.MaxValue;
    159159      foreach (JSSPTask t in tasks) {
    160160        int nrOfRemainingTasks = 0;
    161         foreach (JSSPTask jt in t.Job.Tasks) {
     161        foreach (JSSPTask jt in jobs[t.JobNr.Value].Tasks) {
    162162          if (!jt.IsScheduled.Value)
    163163            nrOfRemainingTasks++;
     
    185185    #endregion
    186186
    187     private ItemList<JSSPTask> GetEarliestNotScheduledTasks(ItemList<JSSPJob> jobs) {
     187    public PRVDecoder()
     188      : base() {
     189      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
     190    }
     191
     192    private ItemList<JSSPTask> GetEarliestNotScheduledTasks() {
    188193      ItemList<JSSPTask> result = new ItemList<JSSPTask>();
    189194      foreach (JSSPJob j in jobs) {
     
    198203    }
    199204    private JSSPTask GetTaskWithMinimalEC(ItemList<JSSPTask> earliestTasksList) {
    200       DoubleValue minEct = new DoubleValue(Double.MaxValue);
     205      double minEct = double.MaxValue;
    201206      JSSPTask result = null;
    202207      foreach (JSSPTask t in earliestTasksList) {
    203         DoubleValue ect = ComputeEarliestCompletionTime(t);
    204         if (ect.Value < minEct.Value) {
     208        double ect = resultingSchedule.ComputeEarliestCompletionTime(t, jobs[t.JobNr.Value]);
     209        if (ect < minEct) {
    205210          result = t;
    206211          minEct = ect;
     
    211216    private ItemList<JSSPTask> GetConflictSetForTask(JSSPTask conflictedTask, ItemList<JSSPTask> earliestTasksList) {
    212217      ItemList<JSSPTask> result = new ItemList<JSSPTask>();
    213       DoubleValue conflictedCompletionTime = ComputeEarliestCompletionTime(conflictedTask);
    214       //result.Add(conflictedTask);
     218      double conflictedCompletionTime = resultingSchedule.ComputeEarliestCompletionTime(conflictedTask, jobs[conflictedTask.JobNr.Value]);
    215219      foreach (JSSPTask t in earliestTasksList) {
    216220        if (t.ResourceNr.Value == conflictedTask.ResourceNr.Value) {
    217           if (ComputeEarliestStartTime(t).Value < conflictedCompletionTime.Value)
     221          if (resultingSchedule.ComputeEarliestStartTime(t, jobs[t.JobNr.Value]) < conflictedCompletionTime)
    218222            result.Add(t);
    219223        }
     
    240244      } 
    241245    }
    242     private DoubleValue ComputeEarliestStartTime(JSSPTask t) {
    243       Resource affectedResource = resultingSchedule.Resources[t.ResourceNr.Value];
    244 
    245       DoubleValue lastMachineEndTime = affectedResource.TotalDuration;
    246       DoubleValue previousJoboperationEndTime = new DoubleValue(double.MinValue);
    247       if (t.PreviousTask != null)
    248         previousJoboperationEndTime = t.PreviousTask.EndTime;
    249 
    250       return new DoubleValue(Math.Max(previousJoboperationEndTime.Value, lastMachineEndTime.Value));
    251     }
    252     private DoubleValue ComputeEarliestCompletionTime(JSSPTask t) {
    253       return new DoubleValue(ComputeEarliestStartTime(t).Value + t.Duration.Value);
    254     }
    255     private void AddTaskToSchedule(JSSPTask selectedTask) {
    256       Resource affectedResource = resultingSchedule.Resources[selectedTask.ResourceNr.Value];
    257       selectedTask.StartTime = ComputeEarliestStartTime(selectedTask);
    258       selectedTask.IsScheduled.Value = true;
    259       affectedResource.Tasks.Add(selectedTask);
    260     }
    261246
    262247    public override Schedule CreateScheduleFromEncoding(PRVEncoding solution) {
    263       PRVEncoding priorityRulesVector = solution;
    264 
     248      jobs = (ItemList<JSSPJob>)Jobs.Clone();
    265249      resultingSchedule = new Schedule(new IntValue(Jobs[0].Tasks.Count));
    266250
     
    274258      //GT-Algorithm
    275259      //STEP 0 - Compute a list of "earliest operations"
    276       ItemList<JSSPTask> earliestTasksList = GetEarliestNotScheduledTasks(Jobs);
     260      ItemList<JSSPTask> earliestTasksList = GetEarliestNotScheduledTasks();
    277261      int currentDecisionIndex = 0;
    278262      while (earliestTasksList.Count > 0) {
     
    284268
    285269        //STEP 3 - Select an operation from the conflict set (various methods depending on how the algorithm should work..)
    286         JSSPTask selectedTask = SelectTaskFromConflictSet(conflictSet, priorityRulesVector [currentDecisionIndex++], solution.NrOfRules.Value);
     270        JSSPTask selectedTask = SelectTaskFromConflictSet(conflictSet, solution [currentDecisionIndex++], solution.NrOfRules.Value);
    287271
    288272        //STEP 4 - Adding the selected operation to the current schedule
    289         AddTaskToSchedule(selectedTask);
     273        selectedTask.IsScheduled.Value = true;
     274        resultingSchedule.AddTask(selectedTask, jobs[selectedTask.JobNr.Value]);
    290275
    291276        //STEP 5 - Back to STEP 1
    292         earliestTasksList = GetEarliestNotScheduledTasks(Jobs);
     277        earliestTasksList = GetEarliestNotScheduledTasks();
    293278      }
    294279
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Encodings/PriorityRulesVector/PRVEncoding.cs

    r6177 r6260  
    3737  [Item("Priority Rules Vector Encoding", "Represents a solution for a standard JobShop Scheduling Problem.")]
    3838  [StorableClass]
    39   public class PRVEncoding : IntegerVector, IJSSPEncoding{
     39  public class PRVEncoding : IntegerVector, ISchedulingEncoding{
    4040    [StorableConstructor]
    4141    protected PRVEncoding(bool deserializing) : base(deserializing) { }
     
    6464    public PRVEncoding (IntegerVector iv, IntValue nrOfRules) : base (iv.Length) {
    6565      this.nrOfRules = (IntValue)nrOfRules.Clone();
    66       foreach (int i in iv) {
     66      for (int i = 0; i < iv.Length; i++) {
    6767        this[i] = iv[i];
    6868      }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Evaluators/JSSPEvaluator.cs

    r6177 r6260  
    3232using HeuristicLab.Problems.Scheduling.Encodings;
    3333using HeuristicLab.Operators;
     34using HeuristicLab.Problems.Scheduling.Interfaces;
    3435
    3536
     
    3738  [Item("JSSP Evaluator", "Represents a evaluator class for standard job shop scheduling problems.")]
    3839  [StorableClass]
    39   public abstract class JSSPEvaluator : JSSPOperator, ISingleObjectiveEvaluator {
     40  public abstract class JSSPEvaluator : JSSPOperator, ISchedulingEvaluator {
    4041    [StorableConstructor]
    4142    protected JSSPEvaluator(bool deserializing) : base(deserializing) { }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Evaluators/MakespanEvaluator.cs

    r6177 r6260  
    5050      foreach (Resource r in schedule.Resources) {
    5151        if (r.TotalDuration.Value > quality.Value) {
    52           quality = r.TotalDuration;
     52          quality.Value = r.TotalDuration.Value;
    5353        }
    5454      }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/HeuristicLab.Problems.Scheduling-3.3.csproj

    r6177 r6260  
    5252    <Compile Include="Encodings\JobSequenceMatrix\Crossovers\JSMJOXCrossover.cs" />
    5353    <Compile Include="Encodings\JobSequenceMatrix\Crossovers\JSMCrossover.cs" />
    54     <Compile Include="Encodings\JobSequenceMatrix\Crossovers\JSMOrderCrossover.cs" />
     54    <Compile Include="Encodings\JobSequenceMatrix\Crossovers\JSMOXCrossover.cs" />
    5555    <Compile Include="Encodings\JobSequenceMatrix\Crossovers\JSMSXXCrossover.cs" />
    5656    <Compile Include="Encodings\JobSequenceMatrix\JSMDecoder.cs" />
     
    6060    <Compile Include="Encodings\JobSequenceMatrix\Manipulators\JSMShiftChangeManipulator.cs" />
    6161    <Compile Include="Encodings\JobSequenceMatrix\Manipulators\JSMManipulator.cs" />
    62     <Compile Include="Encodings\JobSequenceMatrix\Manipulators\JSMInsertionManipulator.cs" />
     62    <Compile Include="Encodings\JobSequenceMatrix\Manipulators\JSMSwapManipulator.cs" />
    6363    <Compile Include="Encodings\JSSPCrossover.cs" />
    6464    <Compile Include="Encodings\JSSPDecoder.cs" />
    6565    <Compile Include="Encodings\JSSPEncodingTypes.cs" />
     66    <Compile Include="Encodings\PermutationWithRepetition\Crossovers\PWRGOXCrossover.cs" />
     67    <Compile Include="Encodings\PermutationWithRepetition\Crossovers\PWRCrossover.cs" />
     68    <Compile Include="Encodings\PermutationWithRepetition\Crossovers\PWRPPXCrossover.cs" />
     69    <Compile Include="Encodings\PermutationWithRepetition\Manipulators\PWRUniformOnePositionManipulator.cs" />
     70    <Compile Include="Encodings\PermutationWithRepetition\Manipulators\PWRManipulator.cs" />
     71    <Compile Include="Encodings\PermutationWithRepetition\PWRDecoder.cs" />
     72    <Compile Include="Encodings\PermutationWithRepetition\PWREncoding.cs" />
     73    <Compile Include="Encodings\PermutationWithRepetition\PWRRandomCreator.cs" />
    6674    <Compile Include="Encodings\PriorityRulesVector\Crossovers\PRVSinglePointCrossover.cs" />
    6775    <Compile Include="Encodings\PriorityRulesVector\Crossovers\PRVDiscreteCrossover.cs" />
     
    6977    <Compile Include="Encodings\PriorityRulesVector\PRVEncoding.cs" />
    7078    <Compile Include="Interfaces\IJSSPDecoder.cs" />
    71     <Compile Include="Interfaces\IJSSPOperator.cs" />
     79    <Compile Include="Interfaces\ISchedulingOperator.cs" />
     80    <Compile Include="Interfaces\IPWROperator.cs" />
    7281    <Compile Include="Interfaces\IPRVOperator.cs" />
    7382    <Compile Include="Interfaces\IJSSPEncoding.cs" />
     
    8796    <Compile Include="Resource.cs" />
    8897    <Compile Include="Evaluators\JSSPEvaluator.cs" />
    89     <Compile Include="Interfaces\IJSSPCreator.cs" />
    9098    <Compile Include="JSSPJob.cs" />
    9199    <Compile Include="JobShopSchedulingProblem.cs" />
    92100    <Compile Include="JSSPTask.cs" />
    93101    <Compile Include="Encodings\JSSPOperator.cs" />
    94     <Compile Include="Evaluators\SchedulingEvaluator.cs" />
     102    <Compile Include="Evaluators\JSSPEvaluationAlgorithm.cs" />
    95103    <Compile Include="SchedulingProblem.cs" />
    96104    <Compile Include="Plugin.cs" />
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/JSSPJob.cs

    r6177 r6260  
    5454      return sb.ToString();
    5555    }
     56
     57    internal JSSPTask GetPreviousTask(JSSPTask t) {
     58      if (t.TaskNr.Value == 0)
     59        return null;
     60      else
     61        return Tasks[t.TaskNr.Value - 1];
     62    }
    5663  }
    5764}
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/JSSPTask.cs

    r6177 r6260  
    4242      this.TaskNr = cloner.Clone(original.TaskNr);
    4343      this.IsScheduled = cloner.Clone(original.IsScheduled);
    44       this.Job = cloner.Clone(original.Job);
    45       this.PreviousTask = cloner.Clone(original.PreviousTask);
    46       this.NextTask = cloner.Clone(original.NextTask);
     44      this.JobNr = cloner.Clone (original.JobNr);
    4745    }
    4846    public override IDeepCloneable Clone(Cloner cloner) {
     
    6159      }
    6260    }
    63     public JSSPJob Job { get; set; }
    64     public JSSPTask PreviousTask { get; set; }
    65     public JSSPTask NextTask { get; set; }
     61    public IntValue JobNr { get; set; }
    6662
    67     public JSSPTask (IntValue taskNr, IntValue resNr, DoubleValue duration, JSSPJob j) : base () {
     63
     64    public JSSPTask (IntValue taskNr, IntValue resNr, DoubleValue duration, IntValue jobNr) : base () {
    6865      Duration = duration;
    6966      ResourceNr = resNr;
     
    7168      StartTime = new DoubleValue(0);
    7269      IsScheduled = new BoolValue(false);
    73       Job = j;
     70      JobNr = jobNr;
     71    }
     72
     73    public override string ToString() {
     74      StringBuilder sb = new StringBuilder();
     75      sb.Append("[" + JobNr + "," + ResourceNr + "]");
     76      return sb.ToString();
    7477    }
    7578  }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/JobShopSchedulingProblem.cs

    r6177 r6260  
    4343using HeuristicLab.Problems.Scheduling.Encodings.PriorityRulesVector;
    4444using HeuristicLab.Encodings.IntegerVectorEncoding;
     45using HeuristicLab.Problems.Scheduling.Encodings.PermutationWithRepetition;
    4546
    4647namespace HeuristicLab.Problems.Scheduling {
     
    5354    private JobShopSchedulingProblem(JobShopSchedulingProblem original, Cloner cloner)
    5455      : base(original, cloner) {
    55         operators = original.operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
    5656        this.encodingType = original.encodingType;
    5757        AttachEventHandlers();
     
    8282    #endregion
    8383
    84 
    85     [Storable]
    86     private List<IOperator> operators;
    87 
    8884    [Storable]
    8985    private JSSPEncodingTypes encodingType;
    9086
    9187    public JobShopSchedulingProblem()
    92       : base(new SchedulingEvaluator (), new JSMRandomCreator ()) {
     88      : base(new JSSPEvaluationAlgorithm (), new JSMRandomCreator ()) {
    9389        Parameters.Add(new ValueParameter<ItemList<JSSPJob>>("Jobs", "Jobdata defining the precedence relationships and the duration of the tasks in this JSSP-Instance.", new ItemList<JSSPJob>()));
    9490        Parameters.Add(new OptionalValueParameter<Schedule>("BestKnownSolution", "The best known solution of this JSSP instance."));
     
    10399      if (SolutionCreator.GetType().Equals(typeof(JSMRandomCreator)))
    104100        encodingType = JSSPEncodingTypes.JSMEncoding;
    105       else
    106         encodingType = JSSPEncodingTypes.PRVEncoding;
    107 
     101      else {
     102        if (SolutionCreator.GetType().Equals(typeof(PRVRandomCreator)))
     103          encodingType = JSSPEncodingTypes.PRVEncoding;
     104        else
     105          encodingType = JSSPEncodingTypes.PWREncoding;
     106      }
    108107      InitializeOperators();
    109108    }
     
    122121      if (encodingType == JSSPEncodingTypes.JSMEncoding) {
    123122        Operators.AddRange(ApplicationManager.Manager.GetInstances<IJSMOperator>());
    124         ((SchedulingEvaluator)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<JSMEncoding>(new JSMDecoder(), new MakespanEvaluator());
     123        ((JSSPEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<JSMEncoding>(new JSMDecoder(), new MakespanEvaluator());
    125124      } else {
    126125        if (encodingType == JSSPEncodingTypes.PRVEncoding) {
    127126          Operators.AddRange(ApplicationManager.Manager.GetInstances<IPRVOperator>());
    128           ((SchedulingEvaluator)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PRVEncoding>(new PRVDecoder(), new MakespanEvaluator());
     127          ((JSSPEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PRVEncoding>(new PRVDecoder(), new MakespanEvaluator());
     128        } else {
     129          if (encodingType == JSSPEncodingTypes.PWREncoding) {
     130            Operators.AddRange(ApplicationManager.Manager.GetInstances<IPWROperator>());
     131            ((JSSPEvaluationAlgorithm)this.EvaluatorParameter.ActualValue).InitializeOperatorGraph<PWREncoding>(new PWRDecoder(), new MakespanEvaluator());
     132          }
    129133        }
    130134      }
     
    146150    #region Importmethods
    147151    private List<string> SplitString(string line) {
     152      if (line == null)
     153        return null;
    148154      List<string> data = new List<string>(line.Split(' '));
    149155      List<string> result = new List<string>();
     
    155161
    156162      return result;
     163    }
     164    private int[] GetIntArray(List<string> data) {
     165      int[] arr = new int [data.Count];
     166      for (int i = 0; i < data.Count; i++ ) {
     167        arr[i] = Int32.Parse(data[i]);
     168      }
     169      return arr;
    157170    }
    158171    public void ImportFromORLibrary(string fileName) {
     
    179192            JSSPJob j = new JSSPJob(new IntValue(jobCount));
    180193            for (int i = 0; i < data.Count; i++) {
    181               JSSPTask t = new JSSPTask(new IntValue (i / 2), new IntValue(Int32.Parse(data[i])), new DoubleValue(Double.Parse(data[i + 1])), j);
     194              JSSPTask t = new JSSPTask(new IntValue (i / 2), new IntValue(Int32.Parse(data[i])), new DoubleValue(Double.Parse(data[i + 1])), new IntValue (jobCount));
    182195              if (j.Tasks.Count > 0) {
    183                 t.PreviousTask = j.Tasks[j.Tasks.Count - 1];
    184                 j.Tasks[j.Tasks.Count - 1].NextTask = t;
    185                 t.StartTime = new DoubleValue (t.PreviousTask.EndTime.Value + 2);
     196                t.StartTime = new DoubleValue (j.Tasks[j.Tasks.Count - 1].EndTime.Value + 2);
    186197              }
    187198              j.Tasks.Add(t);
     
    198209      problemFile.Close();
    199210    }
     211
     212    public void ImportJSMSolution(string fileName) {
     213      if (!File.Exists(fileName))
     214        return;
     215      StreamReader solutionFile = new StreamReader(fileName);
     216      //assures that the parser only reads the first solution instance given in the file
     217      bool solutionFound = false;
     218      JSMEncoding solution = new JSMEncoding();
     219      while (!solutionFile.EndOfStream && !solutionFound) {
     220       
     221        string line = solutionFile.ReadLine();
     222        List<string> data = SplitString(line);
     223        if (data.Count > 0 && ((int)data[0][0] >= 48 && (int)data[0][0] <= 57)) {
     224          if (data.Count > 2)
     225            BestKnownQualityParameter.ActualValue = new DoubleValue(Double.Parse(data[2]));
     226          line = solutionFile.ReadLine();
     227          data = SplitString(line);
     228          while (data != null && data.Count > 0 && ((int)data[0][0] >= 48 && (int)data[0][0] <= 57)) {
     229            Permutation p = new Permutation(PermutationTypes.Absolute, GetIntArray (data));
     230            solution.JobSequenceMatrix.Add(p);
     231
     232            line = solutionFile.ReadLine();
     233            data = SplitString(line);
     234          }//while
     235          solutionFound = true;
     236        }//if
     237      }//while
     238      solutionFile.Close();
     239
     240      JSMDecoder decoder = new JSMDecoder();
     241      Schedule result = decoder.CreateScheduleFromEncoding(solution, Jobs);
     242      BestKnownSolution = result;
     243    }
    200244    #endregion
    201245
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Resource.cs

    r6177 r6260  
    4545    public DoubleValue TotalDuration {
    4646      get {
    47         if (Tasks.Count > 0)
    48           return new DoubleValue(Tasks[Tasks.Count - 1].EndTime.Value);
    49         else
    50           return new DoubleValue (0);
     47        double result = 0;
     48        foreach (JSSPTask t in Tasks) {
     49          if (t.EndTime.Value > result)
     50            result = t.EndTime.Value;
     51        }
     52        return new DoubleValue (result);
    5153      }
    5254    }
  • branches/Scheduling/HeuristicLab.Problems.Scheduling/3.3/Schedule.cs

    r6177 r6260  
    4848
    4949    [Storable]
    50     public ItemList<Resource> Resources;
     50    private ItemList<Resource> resources;
     51    public ItemList<Resource> Resources {
     52      get { return resources; }
     53      set {
     54        if (resources != null) DeregisterResourcesEvents();
     55        resources = value;
     56        if (resources != null) RegisterResourcesEvents();
     57        OnResourcesChanged();
     58      }
     59    }
    5160
    5261    [Storable]
     62    private DoubleValue quality;
    5363    public DoubleValue Quality {
    54       get;
    55       set;
     64      get { return quality; }
     65      set {
     66        if (quality != value) {
     67          if (quality != null) DeregisterQualityEvents();
     68          quality = value;
     69          if (quality != null) RegisterQualityEvents();
     70          OnQualityChanged();
     71        }
     72      }
     73    }
     74
     75    public double Makespan {
     76      get {
     77        double quality = 0;
     78        foreach (Resource r in Resources) {
     79          if (r.TotalDuration.Value > quality) {
     80            quality = r.TotalDuration.Value;
     81          }
     82        }
     83        return quality;
     84      }
    5685    }
    5786
     
    6291        Resources.Add(new Resource(new IntValue (i)));
    6392      }
     93    }
     94
     95    #region Events
     96    public event EventHandler QualityChanged;
     97    private void OnQualityChanged() {
     98      var changed = QualityChanged;
     99      if (changed != null)
     100        changed(this, EventArgs.Empty);
     101    }
     102    private void RegisterQualityEvents() {
     103      Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
     104    }
     105    private void DeregisterQualityEvents() {
     106      Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
     107    }
     108    private void Quality_ValueChanged(object sender, EventArgs e) {
     109      OnQualityChanged();
     110    }
     111
     112    public event EventHandler ResourcesChanged;
     113    private void OnResourcesChanged() {
     114      var changed = ResourcesChanged;
     115      if (changed != null)
     116        changed(this, EventArgs.Empty);
     117    }
     118    private void RegisterResourcesEvents() {
     119      Resources.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Resources_PropertyChanged);
     120    }
     121    private void DeregisterResourcesEvents() {
     122      Resources.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(Resources_PropertyChanged);
     123    }
     124    private void Resources_PropertyChanged(object sender, EventArgs e) {
     125      OnResourcesChanged();
     126    }
     127    #endregion
     128
     129    public void AddTask(JSSPTask task, JSSPJob job) {
     130      task.StartTime = new DoubleValue (ComputeEarliestStartTime(task, job));
     131      Resource affectedResource = resources[task.ResourceNr.Value];
     132      int i = 0;
     133      while (i < affectedResource.Tasks.Count && affectedResource.Tasks[i].StartTime.Value < task.StartTime.Value)
     134        i++;
     135
     136      if (i >= affectedResource.Tasks.Count)
     137        affectedResource.Tasks.Add(task);
     138      else
     139        affectedResource.Tasks.Insert(i, task);
     140    }
     141    public double ComputeEarliestStartTime(JSSPTask t, JSSPJob job) {
     142      Resource affectedResource = resources[t.ResourceNr.Value];
     143      double lastMachineEndTime = affectedResource.TotalDuration.Value;
     144      double previousJobTaskEndTime = 0;
     145      JSSPTask previousTask = job.GetPreviousTask(t);
     146      if (previousTask != null)
     147        previousJobTaskEndTime = previousTask.EndTime.Value;
     148
     149      return Math.Max(previousJobTaskEndTime, lastMachineEndTime);
     150    }
     151    public double ComputeEarliestCompletionTime(JSSPTask t, JSSPJob job) {
     152      Resource affectedResource = resources[t.ResourceNr.Value];
     153      return ComputeEarliestStartTime(t, job) + t.Duration.Value;
    64154    }
    65155
Note: See TracChangeset for help on using the changeset viewer.