problem with algorithm Community detection

53 views
Skip to first unread message

philo...@gmail.com

unread,
Dec 15, 2015, 5:57:22 AM12/15/15
to Sparksee
hi, i have a problem with  algorithm Community detection, when i use visual studio with c++, i have created a graph and i would use this algorithm, but visual studio return a problem with identificator,about CommunitiesSCD  identificator didn't declare. but the code without this  algorithm don't return problem
this is a code:


using namespace sparksee::gdb;
int main(int argc, char *argv[])
{SparkseeConfig cfg;
cfg.SetCacheMaxSize(1024);
Sparksee *sparksee = new Sparksee(cfg);
Database * db = sparksee->Create(L"boh.gdb", L"boh");
Session * sess = db->NewSession();
Graph * graph = sess->GetGraph();
type_t peopleTypeId = graph->NewNodeType(L"PEOPLE");
type_t friendTypeId = graph->NewEdgeType(L"FRIEND", true, true);


oid_t peoplev1 = graph->NewNode(peopleTypeId);
oid_t peoplev2 = graph->NewNode(peopleTypeId);
oid_t peoplev3 = graph->NewNode(peopleTypeId);
oid_t peoplev4 = graph->NewNode(peopleTypeId);
oid_t peoplev5 = graph->NewNode(peopleTypeId);
oid_t peoplev6 = graph->NewNode(peopleTypeId);
oid_t peoplev7 = graph->NewNode(peopleTypeId);
oid_t friend1 = graph->NewEdge(friendTypeId, peoplev1, peoplev2);
oid_t friend2 = graph->NewEdge(friendTypeId, peoplev2, peoplev3);
oid_t friend3 = graph->NewEdge(friendTypeId, peoplev1, peoplev3);
oid_t friend4 = graph->NewEdge(friendTypeId, peoplev1, peoplev4);
oid_t friend5 = graph->NewEdge(friendTypeId, peoplev4, peoplev5);
oid_t friend6 = graph->NewEdge(friendTypeId, peoplev6, peoplev4);
oid_t friend7 = graph->NewEdge(friendTypeId, peoplev5, peoplev6);
oid_t friend8 = graph->NewEdge(friendTypeId, peoplev6, peoplev7);
oid_t friend9 = graph->NewEdge(friendTypeId, peoplev7, peoplev3);
CommunitiesSCD commSCD(*sess); commSCD.AddAllEdgeTypes(); commSCD.AddAllNodeTypes(); commSCD.Run(); 
 DisjointCommunities *dcs = commSCD.GetCommunities(); for (sparksee::gdb::int64_t ii = 0; ii < dcs->GetCount(); ii++) { std::cout << "# community: " << ii << " size: " << cc->GetSize(ii) << std::endl; Objects *dcsNodes = dcs->GetNodes(ii); delete dcsNodes; } delete dcs;



delete sess;
delete db;
delete sparksee;
return EXIT_SUCCESS;
}



sorry for my english, and thank you

c3po.ac

unread,
Dec 15, 2015, 10:18:35 AM12/15/15
to Sparksee
Hi,

First of all, you should make sure that the algorithm header is correctly included:

#include "algorithms/CommunitiesSCD.h"

The error you are mentioning is probably raised because you might not be using the algorithms namespace, so you may want to add this:

using namespace sparksee::algorithms;

We have also noticed that you are also using an undeclared "cc" variable where you probably wanted to use dcs.

Another important issue is that the commSCD variable must be deleted before closing the session, otherwise it raises an error:

    CommunitiesSCD *commSCD = new CommunitiesSCD(*sess);
     commSCD
->AddAllEdgeTypes();
     commSCD
->AddAllNodeTypes();
     commSCD
->Run();
     
DisjointCommunities *dcs = commSCD->GetCommunities();

     
for (sparksee::gdb::int64_t ii = 0; ii < dcs->GetCount(); ii++)
     
{

         std
::cout << "# community: " << ii << " size: " << dcs->GetSize(ii)

                 
<< std::endl;
         
Objects *dcsNodes = dcs->GetNodes(ii);
         
delete dcsNodes;
     
}
     
delete dcs;

     
delete commSCD;


Hope this helps!

Best regards

El dimarts, 15 desembre de 2015 11:57:22 UTC+1, philo...@gmail.com va escriure:

philo...@gmail.com

unread,
Dec 15, 2015, 1:26:52 PM12/15/15
to Sparksee
thank you so much for your favor and time, now i have some results.
i used #include "algorithms/CommunitiesSCD.h" but  not using namespace sparksee::algorithms;
sorry i have a question. two really. First  i haven't  to follow user manual for other algorithms. 
and second why i have a massage to "Unhandled exception" after i run debug

Unhandled exception in 0x00007FF9341012E0 (ntdll.dll) in ConsoleApplication2.exe

thanks again and sorry if my questions seem silly

c3po.ac

unread,
Dec 16, 2015, 9:15:01 AM12/16/15
to Sparksee

Hi,

Don't worry at all to ask us questions, we would be glad to help.

Sorry, but I'm not sure if I correctly understood the first question about the other algorithms. Do you mean that you are missing more examples for the other algorithms in the documentation?

About the exception question:

To find the reason of the exception you should try to catch it and print it's message like the following:

try {    
 
     
// The code
 
 
} catch( Exception &ex ) {
     std
::cout << "Exception: " << ex.Message() << std::endl;
 
}


You could get the line that's throwing the exception and then it would be easier to debug and you could also check the log file called (by default) "sparksee.log" for those that are "SEVERE" kind of errors.

Best regards,


El dimarts, 15 desembre de 2015 19:26:52 UTC+1, philo...@gmail.com va escriure:

philo...@gmail.com

unread,
Dec 16, 2015, 1:16:38 PM12/16/15
to Sparksee
hi,

for my first question i solved this problem with your advice, I have tried the other algorithms in the manual, all ok, I would to know where I can find ,if there are ,other examples in c++ or information about sparksee.
for second questions,  the program works but i have this message exception, i don't understand how to solved this problem and how to use the code you have written, Tomorrow I will try again to resolve


Thanks for your help

c3po.ac

unread,
Dec 18, 2015, 4:37:01 AM12/18/15
to spar...@googlegroups.com
Hi,

All the information about Sparksee is included in the User Manual, which is the most extensive source of information we have published. We will definitely try to improve the number of examples for the next versions of the documentation.

Please let us know if we can be of further help.

Best regards


El dimecres, 16 desembre de 2015 19:16:38 UTC+1, philo...@gmail.com va escriure:

philo...@gmail.com

unread,
Dec 21, 2015, 8:28:03 AM12/21/15
to Sparksee
hi,
i am reading the manual and i am trying the algorithm, but i have the problem with short path, i don't have in the output cost number, the executive return no output value, but i don't have error

this is the code:

#include "stdafx.h"
#include "gdb/Sparksee.h"
#include "gdb/Database.h"
#include "gdb/Session.h"
#include "gdb/Graph.h"
#include "gdb/Objects.h"
#include "gdb/ObjectsIterator.h"
#include "algorithms/SinglePairShortestPathDijkstra.h"
#include "algorithms/SinglePairShortestPath.h"
#include <iostream>
#include <string>

using namespace std;

using namespace sparksee::algorithms;
using namespace sparksee::gdb;
int main(int argc, char *argv[])
{
SparkseeConfig cfg;
cfg.SetCacheMaxSize(1024);

Sparksee *sparksee = new Sparksee(cfg);
Database * db = sparksee->Create(L"boh.gdb", L"boh");
Session * sess = db->NewSession();
Graph * graph = sess->GetGraph();
type_t peopleTypeId = graph->NewNodeType(L"PEOPLE");
type_t friendTypeId = graph->NewEdgeType(L"FRIEND", true, true);

oid_t peoplev1 = graph->NewNode(peopleTypeId);
oid_t peoplev2 = graph->NewNode(peopleTypeId);
oid_t peoplev3 = graph->NewNode(peopleTypeId);
oid_t peoplev4 = graph->NewNode(peopleTypeId);
oid_t peoplev5 = graph->NewNode(peopleTypeId);
oid_t peoplev6 = graph->NewNode(peopleTypeId);
oid_t peoplev7 = graph->NewNode(peopleTypeId);
oid_t friend1 = graph->NewEdge(friendTypeId, peoplev1, peoplev2);
oid_t friend2 = graph->NewEdge(friendTypeId, peoplev2, peoplev3);
oid_t friend3 = graph->NewEdge(friendTypeId, peoplev1, peoplev3);
oid_t friend4 = graph->NewEdge(friendTypeId, peoplev1, peoplev4);
oid_t friend5 = graph->NewEdge(friendTypeId, peoplev4, peoplev5);
oid_t friend6 = graph->NewEdge(friendTypeId, peoplev6, peoplev4);
oid_t friend7 = graph->NewEdge(friendTypeId, peoplev5, peoplev6);
oid_t friend8 = graph->NewEdge(friendTypeId, peoplev4, peoplev7);
oid_t friend9 = graph->NewEdge(friendTypeId, peoplev7, peoplev3);

oid_t src = peoplev1;
oid_t dst = peoplev4;
SinglePairShortestPathDijkstra spspd(*sess, src, dst);
spspd.AddAllNodeTypes();
int roadTypeId = graph->FindType(L"ROAD");
int distanceAttrId = graph->FindAttribute(roadTypeId, L"DISTANCE");
spspd.AddWeightedEdgeType(roadTypeId, Outgoing, distanceAttrId);
spspd.SetMaximumHops(4);
spspd.Run();
cout << "safsgcbn\n";
if (spspd.Exists())
{
double cost = spspd.GetCost();
OIDList * nodes = spspd.GetPathAsNodes();
OIDList * edges = spspd.GetPathAsEdges();
cout << "cost:" << cost;
delete nodes;
delete edges;
}

delete sess;
delete db;
delete sparksee;


return EXIT_SUCCESS;
}





Thanks for your help

c3po.ac

unread,
Dec 21, 2015, 9:25:52 AM12/21/15
to Sparksee

Hello,

In your code the type Road that its used in your code here:


int roadTypeId = graph->FindType(L"ROAD");


has not previously been defined, thus it can't work, maybe there is something missing in your code snippet?

Best regards

El dilluns, 21 desembre de 2015 14:28:03 UTC+1, philo...@gmail.com va escriure:

philo...@gmail.com

unread,
Dec 21, 2015, 4:28:39 PM12/21/15
to Sparksee

sorry for my mess

Graph * graph = sess->GetGraph();
type_t peopleTypeId = graph->NewNodeType(L"PEOPLE");
type_t friendTypeId = graph->NewEdgeType(L"FRIEND", true, true);
int distanceAttrId = graph->FindAttribute(friendTypeId, L"DISTANCE");

oid_t peoplev1 = graph->NewNode(peopleTypeId);
        .....................................
oid_t friend1 = graph->NewEdge(friendTypeId, peoplev1, peoplev2);
..................
oid_t src = peoplev1;
oid_t dst = peoplev7;

SinglePairShortestPathDijkstra *spspd = new SinglePairShortestPathDijkstra(*sess, src, dst);
spspd->AddAllNodeTypes();
spspd->AddWeightedEdgeType(friendTypeId, Outgoing, distanceAttrId);
spspd->SetMaximumHops(4);
spspd->Run();

if (spspd->Exists())
{
double cost = spspd->GetCost();
OIDList * nodes = spspd->GetPathAsNodes();
OIDList * edges = spspd->GetPathAsEdges();
cout << "cost " << cost;
delete nodes;
delete edges;
}
delete spspd;
       .............................

i  am solded thank you 

c3po.ac

unread,
Dec 22, 2015, 4:40:07 AM12/22/15
to Sparksee

Hi,

Great, let us know if we can be of further help.

Best regards

El dilluns, 21 desembre de 2015 22:28:39 UTC+1, philo...@gmail.com va escriure:
Reply all
Reply to author
Forward
0 new messages