private bool _debugMode = true; //change to false if sure than args are correct #endregion Fields #region Constructors public IslandConnections(List<int>[] connection, Island[] islands) { // create digraf where every vertex is island[i], and connections corresponds to adjacence list given in 'connection' if (_debugMode == true) { if (connection.Length != islands.Length) { throw new Exception("Both array args must have the same length"); } for (int i = 0; i < connection.Length; i++) { if (connection[i].Any(num => num >= connection.Length)) { throw new Exception("Found wrong connection, index of island " + i + " out of range"); } if (connection[i].Contains(i)) { throw new Exception("Found wrong connection, island -> island for island = " + i); } } } di_graph = new DirectedGraph(islands, connection); }
public void exchangeIndividuals(Island from, List<IIndividual> individuals) { lock (connections) { foreach (Island island in connections.getConnections(from)) island.welcomeNewIndividuals(individuals); } }
public List<Island> GetConnections(Island island) { if (!_islands.Contains(island)) { throw new Exception("Island does not exist"); } int index = Array.IndexOf(_islands, island); List<Island> toReturn = new List<Island>(); foreach (int i in _connections[index]) { toReturn.Add(_islands[i]); } return toReturn; }
public List <Island> GetConnections(Island island) { if (!_islands.Contains(island)) { throw new Exception("Island does not exist"); } int index = Array.IndexOf(_islands, island); List <Island> toReturn = new List <Island>(); foreach (int i in _connections[index]) { toReturn.Add(_islands[i]); } return(toReturn); }
public DirectedGraph(Island[] islands, List<int>[] connection) { this._islands = islands; this._connections = connection; }
public List <Island> getConnections(Island island) { //return all X adjacent to island (such as: island -> X) return(di_graph.GetConnections(island)); }
public List<Island> getConnections(Island island) { //return all X adjacent to island (such as: island -> X) return di_graph.GetConnections(island); }