public QuadAssignment GenerateNeighbor(ISimAnSolution baseSolution) { if (!(baseSolution is QuadAssignment qaSol)) { return(null); } // generate a copy of the existing assignment QuadAssignment neighbor = new QuadAssignment(); foreach (var item in qaSol.AssignmentSolution) { neighbor.AssignmentSolution.Add(item.Key, item.Value); } // exchange one pair of unit-location assignments int unit1 = _rnd.Next(0, QuadAssignment.MaterialFlow.GetLength(0)); int unit2 = _rnd.Next(0, QuadAssignment.MaterialFlow.GetLength(0)); int assignment1 = qaSol.AssignmentSolution[unit1]; int assignment2 = qaSol.AssignmentSolution[unit2]; neighbor.AssignmentSolution[unit1] = assignment2; neighbor.AssignmentSolution[unit2] = assignment1; // calculate objective value and return neighbor neighbor.CalculateFitness(); return(neighbor); }
public QuadAssignment GenerateStartSolution() { //assign each unit to one location (number of units assumed <= number of locations) QuadAssignment startSolution = new QuadAssignment(); for (int u = 0; u < QuadAssignment.MaterialFlow.GetLength(0); u++) { startSolution.AssignmentSolution[u] = u; } startSolution.CalculateFitness(); return(startSolution); }