Example #1
0
        public Network(int noNodes, int benefitChosen, int costChosen, double selectionIntensityChosen, double roleConProbChosen, double roleNeighborConProbChosen, double roleMethodCopyProbChosen, double percentCooperators)
            : base(noNodes, benefitChosen, costChosen, selectionIntensityChosen, roleConProbChosen, roleNeighborConProbChosen, roleMethodCopyProbChosen, percentCooperators)
        {
            //Populate the Network
            for (int i = 0; i < noNodes; i++)
            {
                if (i < totalCooperators)
                {
                    nodeList[i] = new Cooperator(i, benefit, cost, selectionIntensity);
                }
                else
                {
                    nodeList[i] = new Defector(i, selectionIntensity);
                }
            }

            //Create random relations
            Random rng = new Random();

            for (int i = 0; i < noNodes; i++)
            {
                List <int> nodeConnections = new List <int>();
                for (int j = 0; j < noNodes; j++)
                {
                    if (i != j | !(nodeList[i].NeighborIndexes.Contains(j)))
                    {
                        if (rng.Next(0, 2) > 0)
                        {
                            nodeConnections.Add(nodeList[j].Index);
                        }
                    }
                }
                nodeList[i].AddConnections(nodeConnections);
            }
        }
Example #2
0
        public virtual void AddNewNode(int index)
        {
            Random rng = new Random();
            Node   newNode;

            if (index == roleModelIndex)
            {
                roleModelIndex = -1;
                foreach (Node node in nodeList)
                {
                    if (node != null)
                    {
                        if (roleModelIndex == -1)
                        {
                            roleModelIndex = node.Index;
                        }
                        else if (nodeList[roleModelIndex].GetEffectivePayoff() < node.GetEffectivePayoff())
                        {
                            roleModelIndex = node.Index;
                        }
                    }
                }
            }
            List <int> roleModelNeighbors = nodeList[roleModelIndex].NeighborIndexes;
            List <int> newNodeCons        = new List <int>();
            int        roleCopyNum        = rng.Next(0, 100);
            int        roleConNum         = rng.Next(0, 100);
            int        roleNeighborConNum;

            if (IsCooperator(nodeList[roleModelIndex]))
            {
                if (roleCopyNum < (roleMethodCopyProb * 100))
                {
                    newNode           = new Cooperator(index, benefit, cost, selectionIntensity);
                    totalCooperators += 1;
                }
                else
                {
                    newNode = new Defector(index, selectionIntensity);
                }
            }
            else
            {
                if (roleCopyNum < (roleMethodCopyProb * 100))
                {
                    newNode = new Defector(index, selectionIntensity);
                }
                else
                {
                    newNode           = new Cooperator(index, benefit, cost, selectionIntensity);
                    totalCooperators += 1;
                }
            }
            if (roleConNum < (roleConProb * 100))
            {
                newNodeCons.Add(roleModelIndex);
            }
            for (int i = 0; i < roleModelNeighbors.Count; i++)
            {
                roleNeighborConNum = rng.Next(0, 100);
                if (roleNeighborConNum < (roleNeighborConProb * 100))
                {
                    newNodeCons.Add(roleModelNeighbors[i]);
                }
            }
            newNode.AddConnections(newNodeCons);
            nodeList[index] = newNode;
            Console.WriteLine("New node added");
        }