public bool IsWallWithSTTiles() { var startingBuildings = Variables.BuildingsAt(Variables.StartingTile); if (startingBuildings.Count != 1) { return(false); } var targetBuildings = Variables.BuildingsAt(Variables.TargetTile); if (targetBuildings.Count != 1) { return(false); } // if same building on both the starting and target tile if (startingBuildings[0] == targetBuildings[0]) { return(true); } else { var nberCurrent = startingBuildings[0]; var nberTarget = targetBuildings[0]; List <int> toVisit = Variables.GetBuildingsAround(nberCurrent); var visited = new List <int>(); List <int> neighbors; visited.Add(nberCurrent); if (toVisit.Contains(nberTarget)) { return(true); } while (toVisit.Count > 0) { var first = toVisit[0]; toVisit.Remove(first); neighbors = Variables.GetBuildingsAround(first); foreach (var n in neighbors) { if (n == nberTarget) { return(true); } if (!visited.Contains(n)) { toVisit.Add(n); } } visited.Add(first); } return(false); } }
public override Dictionary <int, double> SimulateCost(int currentVariableIndex, Dictionary <int, double[]> variableSimCost) { var simCosts = new Dictionary <int, double>(); int backup = Variables.GetValue(currentVariableIndex); int previousPos = -42; int diff, dummy; foreach (var pos in Variables.PossibleValues(currentVariableIndex)) { if (pos >= 1 && pos == previousPos + 1) { variableSimCost[pos] = variableSimCost[pos - 1]; Variables.Shift(currentVariableIndex, out dummy, out diff); if (diff != 0) { var setBuildings = Variables.BuildingsAt(pos); foreach (var index in setBuildings) { variableSimCost[pos][index] += diff; } } simCosts[pos] = simCosts[pos - 1] + diff; } else { Variables.SetValue(currentVariableIndex, pos); simCosts[pos] = Cost(variableSimCost[pos]); } previousPos = pos; } Variables.SetValue(currentVariableIndex, backup); return(simCosts); }
public override double Cost(double[] variableCost) { double conflicts = 0.0; foreach (var failures in Variables.Failures) { int nbConflict = failures.Value.Length - 1; if (nbConflict > 0 && !failures.Value.Contains("###")) { conflicts += nbConflict; var words = failures.Key.Split(','); var point = new SetVariables.Point(Int32.Parse(words[0]), Int32.Parse(words[1])); var setBuildings = Variables.BuildingsAt(point); foreach (var index in setBuildings) { variableCost[index] += nbConflict; } } } return(conflicts); }
public override double Cost(double[] variableCost) { // count number of buildings misplaced on unbuildable tiles (denoted by ###) double conflicts = 0.0; int nbConflict; foreach (var failures in Variables.Failures) { if (failures.Value.Contains("###")) { nbConflict = failures.Value.Length - 3; conflicts += nbConflict; var words = failures.Key.Split(','); var point = new SetVariables.Point(Int32.Parse(words[0]), Int32.Parse(words[1])); var setBuildings = Variables.BuildingsAt(point); foreach (var index in setBuildings) { variableCost[index] += nbConflict; } } } return(conflicts); }
public override double Cost() { // no building on one of these two tiles: cost of the tile = 6 // a building with no or with 2 or more neighbors: cost of the tile = 3 // two or more buildings on one of these tile: increasing penalties. double conflicts = 0.0; var startingBuildings = Variables.BuildingsAt(Variables.StartingTile); var targetBuildings = Variables.BuildingsAt(Variables.TargetTile); int neighbors; // if same building on both the starting and target tile if (startingBuildings.Count == 1 && targetBuildings.Count == 1 && startingBuildings[0] == targetBuildings[0]) { return(0.0); } if (startingBuildings.Count == 0) { // penalize buildings not placed on the domain for (int i = 0; i < Variables.GetNumberVariables(); ++i) { if (!Variables.IsSelected(i)) { conflicts += 2; } } } else { foreach (var index in startingBuildings) { neighbors = Variables.CountAround(index); if (neighbors != 1) { conflicts += 2; } } } if (targetBuildings.Count == 0) { // penalize buildings not placed on the domain for (int i = 0; i < Variables.GetNumberVariables(); ++i) { if (!Variables.IsSelected(i)) { conflicts += 2; } } } else { foreach (var index in targetBuildings) { neighbors = Variables.CountAround(index); if (neighbors != 1) { conflicts += 2; } } } return(conflicts); }