#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 System.Linq;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Encodings.BinaryVectorEncoding;
using HeuristicLab.Encodings.PermutationEncoding;
namespace HeuristicLab.Problems.Scheduling.CFSAP {
public static class OneOptAssignment {
public static BinaryVector MakeAssignment(Permutation order, BinaryVector assignment, IntMatrix processingTimes, ItemList setupTimes, out int T) {
var oneOptAssignment = (BinaryVector)assignment.Clone();
T = CFSAP.EvaluateAssignment(order, assignment, processingTimes, setupTimes);
while (true) {
var foundBetterSolution = false;
for (var i = 0; i < oneOptAssignment.Length; ++i) {
var newAssignment = (BinaryVector)oneOptAssignment.Clone();
newAssignment[i] = !newAssignment[i];
int newT = CFSAP.EvaluateAssignment(order, newAssignment, processingTimes, setupTimes);
if (newT < T) { // new best solution has been found
oneOptAssignment = newAssignment;
T = newT;
foundBetterSolution = true;
break;
}
}
if (!foundBetterSolution)
return oneOptAssignment;
}
}
}
}