Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 public void exchangeIndividuals(Island from, List<IIndividual> individuals)
 {
     lock (connections)
     {
         foreach (Island island in connections.getConnections(from))
             island.welcomeNewIndividuals(individuals);
     }
 }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 public DirectedGraph(Island[] islands, List<int>[] connection)
 {
     this._islands = islands;
     this._connections = connection;
 }
Esempio n. 6
0
 public List <Island> getConnections(Island island)
 {
     //return all X adjacent to island (such as: island -> X)
     return(di_graph.GetConnections(island));
 }
Esempio n. 7
0
 public List<Island> getConnections(Island island)
 {
     //return all X adjacent to island (such as: island -> X)
     return di_graph.GetConnections(island);
 }