示例#1
0
void ProgramState::printDegrees() {
    cout << "Degrees:" << endl;
    for (unsigned int i = 1; i <= graph.verticesCount(); ++i) {
	Vertex* cur = graph.getVertexById(i);
	cout << cur->degree();
	if (i != graph.verticesCount()) {
	    cout << " ";
	}
    }
    cout << endl;
}
示例#2
0
void ProgramState::exportShellIndexVsDegree(string outputPath) {
    PropertyMap propertyMap;
    computeShellIndex(propertyMap);
    computeDegreeDistribution(propertyMap);

    double shellAuxAcum;
    unsigned int degreeAmount, vertexId;

    VariantsSet shellIndexVsDegree;
    VariantsSet& shellIndex = propertyMap.getPropertySet("shellIndex");
    VariantsSet& degreeDistribution = propertyMap.getPropertySet("degreeDistribution");
    VariantsSet::const_iterator it = degreeDistribution.begin();
    VariantsSet::const_iterator shellIt = shellIndex.begin();
    VariantsSet::const_iterator shellVsDegreeIt;

    while (it != degreeDistribution.end()) {
        shellIndexVsDegree.insert<double>(it->first, 0);
        ++it;
    }

    while (shellIt != shellIndex.end()) {
        vertexId = from_string<unsigned int>(shellIt->first);
        Vertex* v = graph.getVertexById(vertexId);
        shellAuxAcum = shellIndexVsDegree.get_element<double>(to_string<unsigned int>(v->degree()));
        shellIndexVsDegree.insert<double>(to_string<unsigned int>(v->degree()) , shellAuxAcum + from_string<unsigned int>(shellIt->second));

        ++shellIt;
    }

    shellVsDegreeIt = shellIndexVsDegree.begin();
    while (shellVsDegreeIt != shellIndexVsDegree.end()) {
        std::string degree = shellVsDegreeIt->first;
        shellAuxAcum = from_string<double>(shellVsDegreeIt->second);
        degreeAmount = degreeDistribution.get_element<unsigned int>(degree);

        shellIndexVsDegree.insert<double>(degree , shellAuxAcum / (double)degreeAmount);
        ++shellVsDegreeIt;
    }

    GrapherUtils grapherUtils;
    grapherUtils.exportPropertySet(shellIndexVsDegree, outputPath);
}
示例#3
0
void ProgramState::computeBetweenness(PropertyMap& propertyMap) {
    IGraphFactory<Graph, Vertex> *factory;
    IBetweenness<Graph, Vertex>* betweenness;
    IGraphFactory<WeightedGraph, WeightedVertex> *wfactory;
    IBetweenness<WeightedGraph, WeightedVertex>* wbetweenness;
    IDegreeDistribution<WeightedGraph, WeightedVertex>* wdegreeDistribution;
    IDegreeDistribution<Graph, Vertex>* degreeDistribution;

    // Calculate betweenness.
    if (this->weighted){
        wfactory = new WeightedGraphFactory<WeightedGraph, WeightedVertex>();
        wbetweenness = wfactory->createBetweenness(this->weightedGraph);
        IBetweenness<WeightedGraph, WeightedVertex>::BetweennessIterator betweennessIterator = wbetweenness->iterator();
        while (!betweennessIterator.end()) {
                propertyMap.addProperty<double>("betweenness", to_string<unsigned int>(betweennessIterator->first), betweennessIterator->second);
                ++betweennessIterator;
        }
	delete wbetweenness;
    }else{
    	factory = new GraphFactory<Graph, Vertex>();
    	betweenness = factory->createBetweenness(this->graph);
    	IBetweenness<Graph, Vertex>::BetweennessIterator betweennessIterator = betweenness->iterator();
    	while (!betweennessIterator.end()) {
       		propertyMap.addProperty<double>("betweenness", to_string<unsigned int>(betweennessIterator->first), betweennessIterator->second);
        	++betweennessIterator;
    	}
	delete betweenness;
    }

    // Calculate degree distribution.
    if (this->weighted){
        wdegreeDistribution = wfactory->createDegreeDistribution(this->weightedGraph);
        DegreeDistribution<WeightedGraph, WeightedVertex>::DistributionIterator degreeIterator = wdegreeDistribution->iterator();
        while (!degreeIterator.end()) {
                propertyMap.addProperty<double>("degreeDistribution", to_string<unsigned int>(degreeIterator->first), degreeIterator->second);
                propertyMap.addProperty<double>("degreeDistributionProbability", to_string<unsigned int>(degreeIterator->first), degreeIterator->second / (double)graph.verticesCount());
                ++degreeIterator;
        }
        delete degreeDistribution;
    } else {
	degreeDistribution = factory->createDegreeDistribution(graph);
    	DegreeDistribution<Graph, Vertex>::DistributionIterator degreeIterator = degreeDistribution->iterator();
    	while (!degreeIterator.end()) {
        	propertyMap.addProperty<double>("degreeDistribution", to_string<unsigned int>(degreeIterator->first), degreeIterator->second);
        	propertyMap.addProperty<double>("degreeDistributionProbability", to_string<unsigned int>(degreeIterator->first), degreeIterator->second / (double)graph.verticesCount());
        	++degreeIterator;
    	}
    	delete degreeDistribution;
    }


    double betweennessAuxAcum;
    unsigned int degreeAmount;
    VariantsSet betweennessVsDegree;
    VariantsSet& betweennessSet = propertyMap.getPropertySet("betweenness");
    VariantsSet& degreeDistributionSet = propertyMap.getPropertySet("degreeDistribution");
    VariantsSet::const_iterator it = degreeDistributionSet.begin();
    VariantsSet::const_iterator betwennessIt = betweennessSet.begin();
    VariantsSet::const_iterator betweennessVsDegreeIt;
    while (it != degreeDistributionSet.end())
    {
        betweennessVsDegree.insert<double>(it->first, 0.0);
        ++it;
    }
    while (betwennessIt != betweennessSet.end())
    {
        unsigned int vertedId = from_string<unsigned int>(betwennessIt->first);
        //Vertex* v = graph.getVertexById(vertedId);
	Vertex* v = this->weighted ? weightedGraph.getVertexById(vertedId) : graph.getVertexById(vertedId);
        betweennessAuxAcum = betweennessVsDegree.get_element<double>(to_string<unsigned int>(v->degree()));
        betweennessVsDegree.insert<double>(to_string<unsigned int>(v->degree()) , betweennessAuxAcum + from_string<unsigned int>(betwennessIt->second));

        ++betwennessIt;
    }


    betweennessVsDegreeIt = betweennessVsDegree.begin();
    while (betweennessVsDegreeIt != betweennessVsDegree.end())
    {
        std::string degree = betweennessVsDegreeIt->first;
        betweennessAuxAcum = from_string<double>(betweennessVsDegreeIt->second);
        degreeAmount = degreeDistributionSet.get_element<unsigned int>(degree);

        propertyMap.addProperty<double>("betweennessVsDegree", degree, betweennessAuxAcum / (double)degreeAmount);
        ++betweennessVsDegreeIt;
    }
}