confusion with SharedNetwork->edgeCount() and addEdge()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

confusion with SharedNetwork->edgeCount() and addEdge()

Martin Dimitrov
Hi, 

I am having issues with not being able to account for all the edges that I have added to my graph, as well as some question about adding edges in general. 

1) Lets say I have 2 agents: agent0 and agent1. Say agent0 is local to rank 0 and agent1 is remote. 
I have borrowed agent1 to my network on rank0 and I have created an edge using 
agentNetwork->addEdge(agent0, agent1);
Now, on my other rank, rank1 - should I add this edge as well? Or is it propagated automatically after I do: synchronizeProjectionInfo ?

2) My second question is related to the fact that I do not understand the output of SharedNetwork->edgeCount(). 
In the simplified example below, my SharedNetwork does not contain any edges. Then, I scan a vector of edges and I add them to my SharedNetwork. I have ensured that both the "left" and the "right" agents are present in my context (by borrowing any agents that are remote). 


        for(size_t i = 0; i < edges.size(); i++){
               
                SIRAgent* agent0 = context.getAgent(edges[i].left);
                SIRAgent* agent1 = context.getAgent(edges[i].right);

                agentNetwork->addEdge(agent0, agent1);
        }
    
After this loop is done, I check how many edges total does my graph contain and the number does not add up. There are fewer edges in edgeCount() than the number of times that I have invoked the function addEdge(). (and addEdge() does not add duplicated edges)


int n = agentNetwork->edgeCount();
int n_global = 0; 
MPI_Reduce(&n, &n_global, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
 if( 0 == rank)
 {
        std::cout << " n_global "<< n_global << std::endl;
  }


Thank you very much!
Martin

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: confusion with SharedNetwork->edgeCount() and addEdge()

Murphy, John T.

Hi Martin,

 

The answer to your question 1 is that the edge will be created when you perform a ‘SynchronizeProjectionInfo’; you do not need to create it on both processes. (In fact, creating it on both processes can be considered an error. For example, suppose you created an edge on Process 0 with a weight of ‘1’ and another equivalent edge on Process 1 with a weight of ‘2’; which one is correct? Repast HPC provides a way to flag and then manually resolve this, but there is no automated way to decide which of the two is correct.)

 

I’m not sure about your second question, but one thing I would make sure of is that you are not connecting edges that would involve two non-local agents. Suppose you are running the code on Process 3 and you connect an edge with Agent A (borrowed from Process 0) and Agent B (borrowed from Process 1). This is technically OK- Repast HPC will not throw an error- but as with all changes to non-local agents, it’s risky, because Repast HPC will replace non-local agents or remove them from the process however it needs to for synchronization. This can include dropping both the non-local agents and losing the fact that they were connected. A connected edge should include two local agents or one local and one non-local agent. If a non-local agent is connected to a local one, care should be taken that the connection is only made on one process; if the same pair of agents exist on another process (perhaps with the local/non-local status reversed) the edge should not be created on both processes, as per question 1.

 

Hope this helps- best,

John

 

 

John T. Murphy
Computational Social Scientist
Argonne National Laboratory
& University of Chicago
Computation Institute
[hidden email]
630-252-3453

 

From: "Ozik, Jonathan" <[hidden email]>
Date: Monday, March 13, 2017 at 3:21 PM
To: "Murphy, John T." <[hidden email]>, "Collier, Nicholson T." <[hidden email]>
Subject: Fwd: [Repast-interest] confusion with SharedNetwork->edgeCount() and addEdge()

 

In case you missed it, I assume that one of you knows that answer to this?



Begin forwarded message:

 

From: Martin Dimitrov <[hidden email]>

Subject: [Repast-interest] confusion with SharedNetwork->edgeCount() and addEdge()

Date: March 12, 2017 at 9:46:40 PM CDT

 

Hi, 

 

I am having issues with not being able to account for all the edges that I have added to my graph, as well as some question about adding edges in general. 

 

1) Lets say I have 2 agents: agent0 and agent1. Say agent0 is local to rank 0 and agent1 is remote. 

I have borrowed agent1 to my network on rank0 and I have created an edge using 

agentNetwork->addEdge(agent0, agent1);

Now, on my other rank, rank1 - should I add this edge as well? Or is it propagated automatically after I do: synchronizeProjectionInfo ?

 

2) My second question is related to the fact that I do not understand the output of SharedNetwork->edgeCount(). 

In the simplified example below, my SharedNetwork does not contain any edges. Then, I scan a vector of edges and I add them to my SharedNetwork. I have ensured that both the "left" and the "right" agents are present in my context (by borrowing any agents that are remote). 

 

 

        for(size_t i = 0; i < edges.size(); i++){

               

                SIRAgent* agent0 = context.getAgent(edges[i].left);

                SIRAgent* agent1 = context.getAgent(edges[i].right);

 

                agentNetwork->addEdge(agent0, agent1);

        }

    

After this loop is done, I check how many edges total does my graph contain and the number does not add up. There are fewer edges in edgeCount() than the number of times that I have invoked the function addEdge(). (and addEdge() does not add duplicated edges)

 

 

int n = agentNetwork->edgeCount();

int n_global = 0; 

MPI_Reduce(&n, &n_global, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);

 if( 0 == rank)

 {

        std::cout << " n_global "<< n_global << std::endl;

  }

 

 

Thank you very much!

Martin

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest