Example #1
0
static GError* _tgengraph_parseChooseVertex(TGenGraph* g, const gchar* idStr,
        igraph_integer_t vertexIndex) {
    TGEN_ASSERT(g);

    tgen_debug("found vertex %li (%s)", (glong)vertexIndex, idStr);

    GError* error = NULL;

    /* Assure the edges from this choose action have either all weights or no weights. Store in data */
    igraph_es_t edgeSelector;
    igraph_eit_t edgeIterator;

    gint result = igraph_es_incident(&edgeSelector, vertexIndex, IGRAPH_OUT);
    if(result != IGRAPH_SUCCESS) {
        return g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, 
                "igraph_es_incident return non-success code %i", result);
    }

    result = igraph_eit_create(g->graph, edgeSelector, &edgeIterator);
    if(result != IGRAPH_SUCCESS) {
        return g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, 
                "igraph_eit_create return non-success code %i", result);
    }

    /* Get initial case for first edge */
    igraph_integer_t edgeIndex = IGRAPH_EIT_GET(edgeIterator);
    gdouble* weight = _tgengraph_getWeight(g, edgeIndex);
    gboolean lastWeight;
    gdouble totalWeight = 0.0;
    if(weight != NULL) {
        lastWeight = TRUE;
        totalWeight += *weight;
    }
    else {
        lastWeight = FALSE;
    }
    IGRAPH_EIT_NEXT(edgeIterator);

    while (!IGRAPH_EIT_END(edgeIterator)) {
        edgeIndex = IGRAPH_EIT_GET(edgeIterator);
        gdouble* weight = _tgengraph_getWeight(g, edgeIndex);
        gboolean thisWeight;

        if(weight != NULL) {
            thisWeight = TRUE;
            totalWeight += *weight;
        }
        else {
            thisWeight = FALSE;
        }

        /* Assure weights is still constant */
        if (thisWeight != lastWeight){
            igraph_es_destroy(&edgeSelector);
            igraph_eit_destroy(&edgeIterator);
            return g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                    "choose action must have all weights or no weights");
        }

        lastWeight = thisWeight;
        IGRAPH_EIT_NEXT(edgeIterator);
    }
    TGenAction* a = tgenaction_newChooseAction(&error, lastWeight, totalWeight);

    /* clean up */
    igraph_es_destroy(&edgeSelector);
    igraph_eit_destroy(&edgeIterator);

    if(a) {
        _tgengraph_storeAction(g, a, vertexIndex);
    }

    return error;
}
Example #2
0
EdgeSelector EdgeSelector::Incident(int vid, Mode mode) {
  igraph_es_t es;
  SafeCall(igraph_es_incident(&es, vid, static_cast<igraph_neimode_t>(mode)));
  return EdgeSelector(es);
}