Esempio n. 1
0
void destroyBayesNet(BayesNet** refBayesNet) {
	BayesNet* bayesnet = *refBayesNet;

	int i;
	int n = bnsize(bayesnet);

	// Destrói o grafo
	destroyGraph(&(bayesnet->graph));

	// Destrói os potenciais
	if (bayesnet->potentials!=NULL) {
		for (i=0;i<n;i++) {
			if (bayesnet->potentials[i]!=NULL) destroyPotential(&(bayesnet->potentials[i]));
		}
		free(bayesnet->potentials);
		bayesnet->potentials = NULL;
	}

	// Destrói as variáveis
	if (bayesnet->variables!=NULL) {
		for (i=0;i<n;i++) {
			if (bayesnet->variables[i]!=NULL) destroyVariable(&(bayesnet->variables[i]));
		}
		free(bayesnet->variables);
		bayesnet->variables = NULL;
	}

	// Libera o objeto principal
	free(bayesnet);
	bayesnet = NULL;
	refBayesNet = NULL;
}
Esempio n. 2
0
void freeResources(Agent agents[], Graph g){
    int i;
    for(i=0;i<=NUM_DETECTIVES;i++){
        destroyAgent(agents[i]);
    }
    destroyGraph(g);
}
Esempio n. 3
0
int main(int argc, char **argv) {
    srand(time(NULL));
    
    if (argc < 2) {
        printf("Mandatory parameter is missing. 0 - Generate Kruskal testcase; 1 - Generate Trading Salesman testcase.\n");
    } else if (atoi(argv[1]) == 0) {
        if (argc != 7)
            printf("Usage: 0 nbNodes nbEdges minWeight maxWeight outputName.\n");
        else {
            graph graph = createGraph(atoi(argv[2]), atoi(argv[3]), atof(argv[4]), atof(argv[5]));

            printGraph(&graph, argv[6]);
            //printDot(&graph, 1);

            destroyGraph(&graph);
        }
    } else if (atoi(argv[1]) == 1) {
        if (argc != 4)
            printf("Usage: 1 nbNodes outputName.\n");
        else {
            point *points = generatePoints(atoi(argv[2]));

            printGraphOfPoints(points, atoi(argv[2]), argv[3]);

            destroyPoints(points);
        }
    } else {
        printf("Illegal job id.\n");
        return 0;
    }

    return 0;
}
Esempio n. 4
0
// Constrói o Moral Graph
Graph* buildBNMoralGraph (int nxr, int* xr, BayesNet* bayesnet) {
	
	Graph* subgraph;
	Graph* moral;

	// Variáveis auxiliares
	Vertex* vertex;
	VertexNode* current;
	VertexLinkedList* children;

	int* varmap;	// Mapea as variáveis da rede antiga para a subrede

	int i,j;

	// Aloca o espaço para o mapa de variáveis
	varmap = malloc(bnsize(bayesnet)*sizeof(int));

	// Inicializa o mapa de variáveis
	for (i=0;i<bnsize(bayesnet);i++) varmap[i] = 0;

	// 1. Constroi o subgrafo - mantendo os ids dos nós
	// Inicializa o subgraph
	subgraph = newGraph(DIRECTED_GRAPH);

	// Percore o vetor de variáveis requireds e cria os vértices da subrede
	for (i=0;i<nxr;i++) {
		// Atualiza o mapa de variáveis indicando que o nó/variável é requirida
		varmap[xr[i]] = 1;
		// inclui o nó na rede
		vertex = buildVertex(xr[i],bayesnet->variables[xr[i]]->name);
		addVertex(&subgraph,&vertex);
	}

	for (i=0;i<nxr;i++) {

		// Estabelece as ligações
		vertex = getVertex(&bayesnet->graph,xr[i]);
		current = getVertexChildren(vertex)->first;
		while (current!=NULL) {
			if (varmap[current->vertex->id]==1) addArcByIds(&subgraph,xr[i],current->vertex->id);
			current = current->next;
		}
	}

	// 2. Gera o Moral Graph para o subgraph
	moral = buildMoralGraph(subgraph);

	// Desloca os espaços da memória;
	// Mapa de variáveis
	free(varmap);
	varmap = NULL;

	// Destroy o subgraph
	destroyGraph(&subgraph);
	subgraph = NULL;

	return moral;
}
Esempio n. 5
0
void testGraph(void) {
    printf("Testing graph 1...\n");
    Location path[NUM_MAP_LOCATIONS];
    int a = findShortestPath(NANTES, MARSEILLES, path, ANY,0);
    assert(a == 3);
    assert(path[0] == NANTES);
    assert(path[1] == CLERMONT_FERRAND);
    assert(path[2] == MARSEILLES);
    printf("Test passed!\n");
    printf("Testing graph 2...\n");
    a = findShortestPath(NANTES, MARSEILLES, path, ANY,0);
    assert(a == 3);
    assert(path[0] == NANTES);
    assert(path[1] == CLERMONT_FERRAND);
    assert(path[2] == MARSEILLES);
    printf("Test passed!\n");
    printf("Testing graph by rail...\n");
    a = findShortestPath(MADRID, BARCELONA, path, ANY,2);
    assert(a == 2);
    assert(path[0] == MADRID);
    assert(path[1] == BARCELONA);
    printf("Passed by rail test\n");
    a = findShortestPath(MARSEILLES, COLOGNE, path, ANY,3);
    assert(a == 2);
    assert(path[0] == MARSEILLES);
    assert(path[1] == COLOGNE);
    printf("Passed second rail test\n");
    a = findShortestPath(MARSEILLES, AMSTERDAM, path, ANY,3);
    assert(a == 3);
    assert(path[0] == MARSEILLES);
    assert(path[1] == COLOGNE);
    assert(path[2] == AMSTERDAM);
    printf("Passed final rail test\n");
    printf("Testing fail cases\n");
    printf("Testing Strassburg to CD\n");
    a = findShortestPath(STRASBOURG, CASTLE_DRACULA, path, ANY, 3);
    int i = 0;
    int correct[5] = {51,6,10,21,13};
    for (i = 0; i < a; i++) {
        assert(path[i] == correct[i]);
    }
    printf("Passed\nNow testing same path but without rail (ie round rem 4 equal to 0 )");
    printf("Passed\nNow testing same path but without rail");
    a = findShortestPath(STRASBOURG, CASTLE_DRACULA, path, ANY, 0);
    int correct2[6] = {51,38,58,10,28,13};
    for (i = 0; i < a; i++) {
        assert(path[i] == correct2[i]);
    }
    printf("\nTest Passed\nNow to test the results of connected locs Klaus (expecting CD to be there)\n");
    Graph g = newGraph();
    LocationID *b = connectedLocations(&a, KLAUSENBURG, 0, 0, ANY, g);
    for (i=0; i<a; i++) {
        printf("[%d]",b[i]);
    }
    free(b);
    destroyGraph(g);
    printf("\nDone\n");
}
Esempio n. 6
0
void testConstructDFA1(){
	regexps = malloc(sizeof(struct REentry));
	regexps->regexp = "1*|a";
	regexps->action = "printf;";
	constructNFA();
	constructDFA();
	printDFATransTable();
	destroyNFA();
	destroyDFA();
	destroyGraph();
}
Esempio n. 7
0
void generateBiconnectedGraph(int n, int c, char *graphOutput, char *verificationOutput) {
	FILE *gOut= fopen(graphOutput, "w");
	FILE *vOut= fopen(verificationOutput, "w");

	int cn = n / c;
	int i;
	int max = 0;
	int min = 0;
	
	fprintf(gOut, "%d\n", n);
	for(i = 0; i < n; i++) {
		fprintf(gOut, "%d\n", i);
	}
	for(i = 0; i < c; i++) {
		// Build a biconnected component
		min = i * cn;
		max = min + cn;

		Graph *component = generateBiconnectedComponent(min, max, vOut);

		// Output the edges of the component
		int v;
		for(v = 0; v < component->numVertices; v++) {
			fprintf(gOut, "%s", component->array[v].label);
			AdjListNode *node = component->array[v].adjListHead;
			while(node) {
		        fprintf(gOut, "-%s", component->array[node->index].label);
		        node = node->next;
		    }
		    // Connect it to the last component
		    if(i > 0 && v == 0) {
				fprintf(gOut, "-%d", (min - 1));

				// Also output this egde as an extra biconnected component
				fprintf(vOut, "%d-%d\n", min, (min-1));
				fprintf(vOut, "%d-%d\n\n", (min-1), min);
			}
		    if(v < component->numVertices - 1) {
		    	fprintf(gOut, "\n");
		    }
		}

		if(i < c - 1) {
			// Add an edge between the first node of the next component and the last edge of this component
			fprintf(gOut, "-%d\n", max);
		}

		destroyGraph(component);
	}

	fclose(gOut);
	fclose(vOut);
}
Esempio n. 8
0
void testConstructDFA2(){
	regexps = malloc(sizeof(struct REentry));
	char *s = "(a|b)*abb(a|b)*";
	regexps->regexp = malloc(strlen(s));
	strcpy(regexps->regexp, s);
	regexps->action = "printf;";
	regexps->next = NULL;
	preprocess();
	constructNFA();
	constructDFA();
	printDFATransTable();
	destroyDFA();
	destroyNFA();
	destroyGraph();
}
Esempio n. 9
0
int main(int argc, char * argv[]){
    
    Graph g;
    printf("Test newGraph\n");
    g = newGraph();    
    showGraph(g);
    assert(numV(g) == NUM_MAP_LOCATIONS);
    assert(numE(g,LAND) == 17);
    assert(numE(g, SEA) == 8);
    showIsAdjacent(g);
    printf("Passed\n");
    printf("Destroying graph\n");
    destroyGraph(g);
    printf("Finished destroy \n");
    return 0;
}
Esempio n. 10
0
int main(int argc, char *argv[]) {
    // Check that all params are given
    if(argc != 2) {                             
        fprintf(stderr, "Usage: ./bic graphFile\n");
        return 1;
    }

    // Parse the input file and generate graph
    char* filename = argv[1];
    Graph *graph = parseGraphFile(filename);

    // Find biconnected components
    bicc(graph);

    destroyGraph(graph);
}
Esempio n. 11
0
int main(int argc, char ** argv) {
  Roomy_init(&argc,&argv);
  
	if(createGraph() &&
		 destroyGraph() && 
		 addNode() &&
		 containsNodeTest() &&
		 addMultipleNodes() &&
		 ableToAddMoreThanInitialSize() &&
		 addingSameNodeDoesntIncreaseCount() &&
		 addEdgeTest()) {
    printf("All tests passed\n");
  } else {
    printf("ERROR OCCURRED... SEE LOGS\n");
  }
	
	Roomy_finalize();
}
Esempio n. 12
0
int main(int argc, char const *argv[])
{
	/* code */
	char* line = NULL;
	size_t bytes = 0;
	int* solveSet = NULL, k = 0;
	Graph* graph = NULL;
	while(getline(&line, &bytes, stdin) != EOF)
	{
		graph = readGraph(line);
		k = solveVertexCover_SAT(graph, solveSet);
		printSolveSet(solveSet, k);
		free(solveSet);
		solveSet = NULL;
		destroyGraph(&graph);
	}

	return 0;
}
Esempio n. 13
0
void destroyTrustGraph(Graph * trustGraph)
{
    List *l;
    int i,j;
    Person *p;
    for(i=0; i<trustGraph->size;i++)
    {
    	for(j=0; j<trustGraph->position[i]; j++)
    	{
    		p = trustGraph->table[i][j]->obj;
    		l = p->list;
    		while(l != NULL)
    		{
    			free(l->neighbor->eProp->prop[1]);
    			l= l->next;
    		}
    	}
    }
    destroyGraph(trustGraph);
}
Esempio n. 14
0
int main(int argc, char * argv[]){
    if (argc < 2){ 
        printf("Incorrect usage: must enter filename\n");
        exit (1);
    }
    Graph g = readGraph(argv[1]);
    showGraph(g);
    printf("\n");

    // TASK 1
    printf("TASK 1\n");
    showGraphLabels(g);
    printf("\n");
    showData(g);
    printf("\n");
    
    // TASK 2
    printf("TASK 2\n");
    int *dfsOrdered = malloc(numV(g) * sizeof(Vertex));
    dfSearch2(g, dfsOrdered);
    int i;
    for(i=0;i< cnt;i++){
        Vertex v = dfsOrdered[i];
        showVertexData(g,v);
    }
    printf("\n");
    
    // TASK 3
    printf("TASK 3\n");
    printf("\nFlying all over the world\n");

    //Uncomment out this line when you get to task 3
    getFlights(g,dfsOrdered);
    
    free(dfsOrdered);    
    destroyGraph(g);    
    return 0;
}
Esempio n. 15
0
void graphAlgorithms::newGraph(int vertCount)
{
	if(vertCount < 5) {
	  std::cout << "newGraph: Error, invalid graph size.\n";
  }else{
		//free any existing memory
		destroyGraph();
		//allocate new adjacency matrix
    graphMatrix = new int*[vertCount];
    for(int i = 0; i < vertCount; i++)
      graphMatrix[i] = new int[vertCount];
    //set all elements in matrix to zero
    for(int r = 0; r < vertCount; r++)
      for(int c = 0; c < vertCount; c++)
        graphMatrix[r][c] = 0;

    dist = new int[vertCount];
    topoNodes = new int[vertCount];	


    vertexCount = vertCount;
	}
}
Esempio n. 16
0
void decideMove (HunterView gameState) {
    printf("at start of code\n"); fflush(stdout);
	Graph g = newGraph();
    char *locations[] = {
        "AL", "AM", "AT", "BA", "BI", "BE", "BR", "BO", "BU", "BC", 
        "BD", "CA", "CG", "CD", "CF", "CO", "CN", "DU", "ED", "FL",
        "FR", "GA", "GW", "GE", "GO", "GR", "HA", "JM", "KL", "LE",
        "LI", "LS", "LV", "LO", "MA", "MN", "MR", "MI", "MU", "NA",
        "NP", "NU", "PA", "PL", "PR", "RO", "SA", "SN", "SR", "SJ",
        "SO", "ST", "SW", "SZ", "TO", "VA", "VR", "VE", "VI", "ZA",
        "ZU", "NS", "EC", "IS", "AO", "BB", "MS", "TS", "IO", "AS", 
        "BS", "C?", "S?", "HI", "D1", "D2", "D3", "D4", "D5", "TP"
	};
	int round = getRound(gameState);
	PlayerID id = getCurrentPlayer(gameState);
    LocationID move = getLocation(gameState, id);
    printf("the original loc is %d and health %d\n",move,getHealth(gameState,id));
	char * msg = "";
    printf("initialised all variables\n"); fflush(stdout);
	//set initial locations
	if (round - id == 0) {
	    if (id == PLAYER_LORD_GODALMING) {move = CASTLE_DRACULA; msg = "camping";}
	    else if (id == PLAYER_DR_SEWARD)  move = BELGRADE;
	    else if (id == PLAYER_VAN_HELSING) move = STRASBOURG;
	    else if (id == PLAYER_MINA_HARKER) move = MADRID;
	    registerBestPlay(locations[move], msg);
	    destroyGraph(g);
	    return;
    }
    printf("done initial moves\n"); fflush(stdout);

    //below code will throw errors if LG is killed
    //if (id == PLAYER_LORD_GODALMING) { registerBestPlay("CD","I'm camping MAN!!!"); return; }
	srand (time(NULL));
	int path[NUM_MAP_LOCATIONS];
    int amtLocs = 0;
    LocationID * adj = connectedLocations(&amtLocs, getLocation(gameState, id), id, round, ANY, g);
    LocationID target = UNKNOWN_LOCATION;
    int camper = 0, i, j;
    printf("setting up connected locs etc\n"); fflush(stdout);

    // check for campers
    // if the current player is camping, then the player
    // will stay camping and ai will return
    
    for (i = 0; i < NUM_HUNTERS; i++) {
        if (getLocation(gameState, i) == CASTLE_DRACULA) {
            camper = 1;
            if (id == i) {
	            registerBestPlay("CD", "Staying camping");
                destroyGraph(g);
                free(adj);
                return; 
            }
        }
    } 

    if (!camper) { //if no camper and hunter is shortest dist to castle dracula, move towards castle dracula
        int hunterDist[NUM_HUNTERS] = {UNKNOWN_LOCATION,UNKNOWN_LOCATION,UNKNOWN_LOCATION,UNKNOWN_LOCATION};
        int closestHunter = PLAYER_LORD_GODALMING;
        for (i = PLAYER_LORD_GODALMING; i < NUM_HUNTERS; i++) {
            hunterDist[i] = findShortestPath(getLocation(gameState, i), CASTLE_DRACULA, path, ANY, round);
            if (hunterDist[i] == -1) hunterDist[i] = 1000; //-1 is when there is no path, so don't want him to be shortest
            if ((hunterDist[closestHunter] > hunterDist[i]) || (hunterDist[closestHunter] == UNKNOWN_LOCATION)) closestHunter = i;
        }
        if (closestHunter == id) move = path[1];
    } else {
        LocationID draculaLoc[TRAIL_SIZE];
        getHistory (gameState, PLAYER_DRACULA, draculaLoc); //updates Dracula trail

        for (i = TRAIL_SIZE - 1; i >= 0 ; i--) //locations newer in trail will override older ones
            target = dracTarget(draculaLoc, i); //we have any useful info on his location...

        if (target != UNKNOWN_LOCATION) {
            //Note: Dracula cannot visit any location currently in his trail - hunters should not visit target itself!
            int pathLen = findShortestPath(getLocation(gameState, id), target, path, ANY, round); //success is any number not -1
        	if (getLocation(gameState, id) != target && pathLen != -1) { //path found, and not at rest on target (Drac's trail)
                if (path[1] != target) move = path[1]; 
                //don't move into Dracula's trail (see note above)
                else move = adj[rand() % amtLocs];
                for (i = 0; i < TRAIL_SIZE ; i++) if (path[1] == dracTarget(draculaLoc, i)) move = adj[rand() % amtLocs];
            } else move = adj[rand() % amtLocs];
		} else { //prevents doubling up of hunters when making a random move, since Dracula 404
            int occupied = 0, newLoc = UNKNOWN_LOCATION;
            move = adj[rand() % amtLocs];
            for (j = 0; j < NUM_HUNTERS; j++) if (move == getLocation(gameState, j)) occupied = 1;
            if (occupied) { 
                for (i = 0; i < amtLocs; i++) { 
                    occupied = 0;
                    for (j = 0; j < NUM_HUNTERS; j++) if (adj[i] == getLocation(gameState, j)) occupied = 1;
                    if (!occupied) {newLoc = i; break;}
                }
            }
            if (newLoc != UNKNOWN_LOCATION) move = adj[newLoc]; 
        }
    } 
    if (target != UNKNOWN_LOCATION) printf("*Moving from %s (%d) to target %s (%d) via %s (%d)*\n", locations[getLocation(gameState, id)], getLocation(gameState, id), locations[target], target, locations[move], move);
    else printf("*No target - moving from %s (%d) to %s (%d)*\n", locations[getLocation(gameState, id)], getLocation(gameState, id), locations[move], move);
    
	if (isLegalMove(gameState, id, move, round, g)) registerBestPlay(locations[move], "");
	else {
        printf("ERROR: Location is invalid! Registering default rest move...");
        registerBestPlay(locations[getLocation(gameState, id)], "");
    }
    destroyGraph(g);
    free(adj);
}
Esempio n. 17
0
int main()
{
    printf("Starting tests...\n");
    test_creatememory();
    Graph_p undir_graph = test_createGraph(UNDIRECTED);
    test_addGraphElement(undir_graph, 0, 26); // 20 should pass 6 should require memory reallocation
    test_addEdge(undir_graph, 0, 1, 1);
    test_addEdge(undir_graph, 0, 4, 2);
    test_addEdge(undir_graph, 1, 2, 3);
    test_addEdge(undir_graph, 1, 3, 4);
    test_addEdge(undir_graph, 1, 4, 5);
    test_addEdge(undir_graph, 2, 3, 6);
    test_addEdge(undir_graph, 3, 4, 7);
    test_createGraphPage(undir_graph);
    test_addGraphElement(undir_graph, 1, 6); // Add 6 more - should pass now
    test_addEdge(undir_graph, 4, 0, 8);
    test_addEdge(undir_graph, 13, 0, 9);
    test_addEdge(undir_graph, 13, 0, 10);
    test_addEdge(undir_graph, 5, 0, 11);
    test_addEdge(undir_graph, 6, 0, 12);
    test_addEdge(undir_graph, 7, 0, 13);
    test_addEdge(undir_graph, 8, 0, 14);
    test_addEdge(undir_graph, 9, 0, 15);
    test_addEdge(undir_graph, 13, 0, 9); // duplicate
    test_addEdge(undir_graph, 10, 0, 16);
    test_addEdge(undir_graph, 11, 0, 17);
    test_addEdge(undir_graph, 13, 0, 9); // duplicate
    test_addEdge(undir_graph, 12, 0, 18);

    //get edges of Node(0)
    

    
    
/*
    Graph_p dir_graph = createGraph(DIRECTED,"./default_d_db.gdb");
    assert(dir_graph != NULL);
    result = addGraphElement(dir_graph, &(c[0]));
    assert(result == OK);
    result = addGraphElement(dir_graph, &(c[1]));
    assert(result == OK);
    result = addGraphElement(dir_graph, &(c[2]));
    assert(result == OK);
    result = addGraphElement(dir_graph, &(c[3]));
    assert(result == OK);
    result = addGraphElement(dir_graph, &(c[4]));
    assert(result == OK);

    result = addEdge(dir_graph, 0, 1, NULL);
    assert(result == OK);
    result = addEdge(dir_graph, 0, 4, NULL);
    assert(result == OK);
    result = addEdge(dir_graph, 1, 2, NULL);
    assert(result == OK);
    result = addEdge(dir_graph, 1, 3, NULL);
    assert(result == OK);
    result = addEdge(dir_graph, 1, 4, NULL);
    assert(result == OK);
    result = addEdge(dir_graph, 2, 3, NULL);
    assert(result == OK);
    result = addEdge(dir_graph, 3, 4, NULL);
    assert(result == OK);
*/
    printf("\nUNDIRECTED GRAPH");
    displayGraph(undir_graph);
    destroyGraph(undir_graph);
    
    //printf("\nDIRECTED GRAPH");
    //displayGraph(dir_graph);
    //destroyGraph(dir_graph);

    return 0;
}
Esempio n. 18
0
graphAlgorithms::~graphAlgorithms()
{
	destroyGraph();
}
Esempio n. 19
0
int main(int argc, char **argv)
{
	ReadSet *sequences = NULL;
	RoadMapArray *rdmaps;
	PreGraph *preGraph;
	Graph *graph;
	char *directory, *graphFilename, *preGraphFilename, *seqFilename,
	    *roadmapFilename;
	double coverageCutoff = -1;
	double maxCoverageCutoff = -1;
	double expectedCoverage = -1;
	int longMultCutoff = -1;
	Coordinate minContigLength = -1;
	Coordinate minContigKmerLength;
	boolean *dubious = NULL;
	Coordinate insertLength[CATEGORIES];
	Coordinate insertLengthLong = -1;
	Coordinate std_dev[CATEGORIES];
	Coordinate std_dev_long = -1;
	short int accelerationBits = 24;
	boolean readTracking = false;
	boolean exportAssembly = false;
	boolean unusedReads = false;
	boolean estimateCoverage = false;
	boolean estimateCutoff = false;
	FILE *file;
	int arg_index, arg_int;
	double arg_double;
	char *arg;
	Coordinate *sequenceLengths = NULL;
	Category cat;
	boolean scaffolding = true;
	int pebbleRounds = 1;
	long long longlong_var;
	short int short_var;

	setProgramName("velvetg");

	for (cat = 0; cat < CATEGORIES; cat++) {
		insertLength[cat] = -1;
		std_dev[cat] = -1;
	}

	// Error message
	if (argc == 1) {
		puts("velvetg - de Bruijn graph construction, error removal and repeat resolution");
		printf("Version %i.%i.%2.2i\n", VERSION_NUMBER,
		       RELEASE_NUMBER, UPDATE_NUMBER);
		puts("\nCopyright 2007, 2008 Daniel Zerbino ([email protected])");
		puts("This is free software; see the source for copying conditions.  There is NO");
		puts("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
		puts("Compilation settings:");
		printf("CATEGORIES = %i\n", CATEGORIES);
		printf("MAXKMERLENGTH = %i\n", MAXKMERLENGTH);
		puts("");
		printUsage();
		return 1;
	}

	if (strcmp(argv[1], "--help") == 0) {
		printUsage();
		return 0;
	}

	// Memory allocation 
	directory = argv[1];
	graphFilename = mallocOrExit(strlen(directory) + 100, char);
	preGraphFilename =
	    mallocOrExit(strlen(directory) + 100, char);
	roadmapFilename = mallocOrExit(strlen(directory) + 100, char);
	seqFilename = mallocOrExit(strlen(directory) + 100, char);
	// Argument parsing
	for (arg_index = 2; arg_index < argc; arg_index++) {
		arg = argv[arg_index++];
		if (arg_index >= argc) {
			puts("Unusual number of arguments!");
			printUsage();
			exit(1);
		}

		if (strcmp(arg, "-cov_cutoff") == 0) {
			if (strcmp(argv[arg_index], "auto") == 0) {
				estimateCutoff = true;
			} else {
				sscanf(argv[arg_index], "%lf", &coverageCutoff);
			}
		} else if (strcmp(arg, "-exp_cov") == 0) {
			if (strcmp(argv[arg_index], "auto") == 0) {
				estimateCoverage = true;
				readTracking = true;
			} else {
				sscanf(argv[arg_index], "%lf", &expectedCoverage);
				if (expectedCoverage > 0)
					readTracking = true;
			}
		} else if (strcmp(arg, "-ins_length") == 0) {
			sscanf(argv[arg_index], "%lli", &longlong_var);
			insertLength[0] = (Coordinate) longlong_var;
			if (insertLength[0] < 0) {
				printf("Invalid insert length: %lli\n",
				       (long long) insertLength[0]);
				exit(1);
			}
		} else if (strcmp(arg, "-ins_length_sd") == 0) {
			sscanf(argv[arg_index], "%lli", &longlong_var);
			std_dev[0] = (Coordinate) longlong_var;
			if (std_dev[0] < 0) {
				printf("Invalid std deviation: %lli\n",
				       (long long) std_dev[0]);
				exit(1);
			}
		} else if (strcmp(arg, "-ins_length_long") == 0) {
			sscanf(argv[arg_index], "%lli", &longlong_var);
			insertLengthLong = (Coordinate) longlong_var;
		} else if (strcmp(arg, "-ins_length_long_sd") == 0) {
			sscanf(argv[arg_index], "%lli", &longlong_var);
			std_dev_long = (Coordinate) longlong_var;
		} else if (strncmp(arg, "-ins_length", 11) == 0
			   && strchr(arg, 'd') == NULL) {
			sscanf(arg, "-ins_length%hi", &short_var);
			cat = (Category) short_var;
			if (cat < 1 || cat > CATEGORIES) {
				printf("Unknown option: %s\n", arg);
				exit(1);
			}
			sscanf(argv[arg_index], "%lli", &longlong_var);
			insertLength[cat - 1] = (Coordinate) longlong_var;
			if (insertLength[cat - 1] < 0) {
				printf("Invalid insert length: %lli\n",
				       (long long) insertLength[cat - 1]);
				exit(1);
			}
		} else if (strncmp(arg, "-ins_length", 11) == 0) {
			sscanf(arg, "-ins_length%hi_sd", &short_var);
			cat = (Category) short_var;
			if (cat < 1 || cat > CATEGORIES) {
				printf("Unknown option: %s\n", arg);
				exit(1);
			}
			sscanf(argv[arg_index], "%lli", &longlong_var);
			std_dev[cat - 1] = (Coordinate) longlong_var;
			if (std_dev[cat - 1] < 0) {
				printf("Invalid std deviation: %lli\n",
				       (long long) std_dev[cat - 1]);
				exit(1);
			}
		} else if (strcmp(arg, "-read_trkg") == 0) {
			readTracking =
			    (strcmp(argv[arg_index], "yes") == 0);
		} else if (strcmp(arg, "-scaffolding") == 0) {
			scaffolding =
			    (strcmp(argv[arg_index], "yes") == 0);
		} else if (strcmp(arg, "-amos_file") == 0) {
			exportAssembly =
			    (strcmp(argv[arg_index], "yes") == 0);
		} else if (strcmp(arg, "-min_contig_lgth") == 0) {
			sscanf(argv[arg_index], "%lli", &longlong_var);
			minContigLength = (Coordinate) longlong_var;
		} else if (strcmp(arg, "-accel_bits") == 0) {
			sscanf(argv[arg_index], "%hi", &accelerationBits);
			if (accelerationBits < 0) {
				printf
				    ("Illegal acceleration parameter: %s\n",
				     argv[arg_index]);
				printUsage();
				return -1;
			}
		} else if (strcmp(arg, "-max_branch_length") == 0) {
			sscanf(argv[arg_index], "%i", &arg_int);
			setMaxReadLength(arg_int);
			setLocalMaxReadLength(arg_int);
		} else if (strcmp(arg, "-max_divergence") == 0) {
			sscanf(argv[arg_index], "%lf", &arg_double);
			setMaxDivergence(arg_double);
			setLocalMaxDivergence(arg_double);
		} else if (strcmp(arg, "-max_gap_count") == 0) {
			sscanf(argv[arg_index], "%i", &arg_int);
			setMaxGaps(arg_int);
			setLocalMaxGaps(arg_int);
		} else if (strcmp(arg, "-min_pair_count") == 0) {
			sscanf(argv[arg_index], "%i", &arg_int);
			setUnreliableConnectionCutoff(arg_int);
		} else if (strcmp(arg, "-max_coverage") == 0) {
			sscanf(argv[arg_index], "%lf", &maxCoverageCutoff);
		} else if (strcmp(arg, "-long_mult_cutoff") == 0) {
			sscanf(argv[arg_index], "%i", &longMultCutoff);
			setMultiplicityCutoff(longMultCutoff);
		} else if (strcmp(arg, "-unused_reads") == 0) {
			unusedReads =
			    (strcmp(argv[arg_index], "yes") == 0);
			if (unusedReads)
				readTracking = true;
		} else if (strcmp(arg, "--help") == 0) {
			printUsage();
			return 0;	
		} else {
			printf("Unknown option: %s;\n", arg);
			printUsage();
			return 1;
		}
	}

	// Bookkeeping
	logInstructions(argc, argv, directory);

	strcpy(seqFilename, directory);
	strcat(seqFilename, "/Sequences");

	strcpy(roadmapFilename, directory);
	strcat(roadmapFilename, "/Roadmaps");

	strcpy(preGraphFilename, directory);
	strcat(preGraphFilename, "/PreGraph");

	if (!readTracking) {
		strcpy(graphFilename, directory);
		strcat(graphFilename, "/Graph");
	} else {
		strcpy(graphFilename, directory);
		strcat(graphFilename, "/Graph2");
	}

	// Graph uploading or creation
	if ((file = fopen(graphFilename, "r")) != NULL) {
		fclose(file);
		graph = importGraph(graphFilename);
	} else if ((file = fopen(preGraphFilename, "r")) != NULL) {
		fclose(file);
		sequences = importReadSet(seqFilename);
		convertSequences(sequences);
		graph =
		    importPreGraph(preGraphFilename, sequences,
				   readTracking, accelerationBits);
		sequenceLengths =
		    getSequenceLengths(sequences, getWordLength(graph));
		correctGraph(graph, sequenceLengths);
		exportGraph(graphFilename, graph, sequences->tSequences);
	} else if ((file = fopen(roadmapFilename, "r")) != NULL) {
		fclose(file);
		rdmaps = importRoadMapArray(roadmapFilename);
		preGraph = newPreGraph_pg(rdmaps, seqFilename);
		clipTips_pg(preGraph);
		exportPreGraph_pg(preGraphFilename, preGraph);
		destroyPreGraph_pg(preGraph);

		sequences = importReadSet(seqFilename);
		convertSequences(sequences);
		graph =
		    importPreGraph(preGraphFilename, sequences,
				   readTracking, accelerationBits);
		sequenceLengths =
		    getSequenceLengths(sequences, getWordLength(graph));
		correctGraph(graph, sequenceLengths);
		exportGraph(graphFilename, graph, sequences->tSequences);
	} else {
		puts("No Roadmap file to build upon! Please run velveth (see manual)");
		exit(1);
	}

	// Set insert lengths and their standard deviations
	for (cat = 0; cat < CATEGORIES; cat++) {
		if (insertLength[cat] > -1 && std_dev[cat] < 0)
			std_dev[cat] = insertLength[cat] / 10;
		setInsertLengths(graph, cat,
				 insertLength[cat], std_dev[cat]);
	}

	if (insertLengthLong > -1 && std_dev_long < 0)
		std_dev_long = insertLengthLong / 10;
	setInsertLengths(graph, CATEGORIES,
			 insertLengthLong, std_dev_long);

	// Coverage cutoff
	if (expectedCoverage < 0 && estimateCoverage == true) {
		expectedCoverage = estimated_cov(graph);
		if (coverageCutoff < 0) {
			coverageCutoff = expectedCoverage / 2;
			estimateCutoff = true;
		}
	} else { 
		estimateCoverage = false;
		if (coverageCutoff < 0 && estimateCutoff) 
			coverageCutoff = estimated_cov(graph) / 2;
		else 
			estimateCutoff = false;
	}

	if (coverageCutoff < 0) {
		puts("WARNING: NO COVERAGE CUTOFF PROVIDED");
		puts("Velvet will probably leave behind many detectable errors");
		puts("See manual for instructions on how to set the coverage cutoff parameter");
	}

	dubious =
	    removeLowCoverageNodesAndDenounceDubiousReads(graph,
							  coverageCutoff);
	removeHighCoverageNodes(graph, maxCoverageCutoff);
	clipTipsHard(graph);

	if (expectedCoverage > 0) {
		if (sequences == NULL) {
			sequences = importReadSet(seqFilename);
			convertSequences(sequences);
		}

		// Mixed length sequencing
		readCoherentGraph(graph, isUniqueSolexa, expectedCoverage,
				  sequences);

		// Paired ends module
		createReadPairingArray(sequences);
		for (cat = 0; cat < CATEGORIES; cat++) 
			if(pairUpReads(sequences, 2 * cat + 1))
				pebbleRounds++;

		if (pairUpReads(sequences, 2 * CATEGORIES + 1))
			pebbleRounds++;

		detachDubiousReads(sequences, dubious);
		activateGapMarkers(graph);
		for ( ;pebbleRounds > 0; pebbleRounds--)
			exploitShortReadPairs(graph, sequences, dubious, scaffolding);
	} else {
		puts("WARNING: NO EXPECTED COVERAGE PROVIDED");
		puts("Velvet will be unable to resolve any repeats");
		puts("See manual for instructions on how to set the expected coverage parameter");
	}

	free(dubious);

	concatenateGraph(graph);

	if (minContigLength < 2 * getWordLength(graph))
		minContigKmerLength = getWordLength(graph);
	else
		minContigKmerLength = minContigLength - getWordLength(graph) + 1;		

	strcpy(graphFilename, directory);
	strcat(graphFilename, "/contigs.fa");
	exportLongNodeSequences(graphFilename, graph, minContigKmerLength); 

	strcpy(graphFilename, directory);
	strcat(graphFilename, "/stats.txt");
	displayGeneralStatistics(graph, graphFilename);

	if (sequences == NULL) {
		sequences = importReadSet(seqFilename);
		convertSequences(sequences);
	}

	strcpy(graphFilename, directory);
	strcat(graphFilename, "/LastGraph");
	exportGraph(graphFilename, graph, sequences->tSequences);

	if (exportAssembly) {
		strcpy(graphFilename, directory);
		strcat(graphFilename, "/velvet_asm.afg");
		exportAMOSContigs(graphFilename, graph, minContigKmerLength, sequences);
	}

	if (unusedReads)
		exportUnusedReads(graph, sequences, minContigKmerLength, directory);

	if (estimateCoverage) 
		printf("Estimated Coverage = %f\n", expectedCoverage);
	if (estimateCutoff) 
		printf("Estimated Coverage cutoff = %f\n", coverageCutoff);

	logFinalStats(graph, minContigKmerLength, directory);

	destroyGraph(graph);
	free(graphFilename);
	free(preGraphFilename);
	free(seqFilename);
	free(roadmapFilename);
	destroyReadSet(sequences);
	return 0;
}
Esempio n. 20
0
SigDenseSet * outInside(int flag,char *initial_filename,char *cluster_filename,float par_out_in,SigDenseSet *sds){
	Graph *g,*tg;
	SigDense *sd;
	Node *node, *tnode;
	char line[MAXLINE];
	char clusterName[10];
	char edgesNumber[10];
	char dump[10];
	int orig_degree=0;

	g=readGraph(initial_filename);	//kataskeui tou arxikou grafou
	

	if(flag==0){	//einai i proti methodos pou efarmozetai, diavasma apo to intermediate arxeio
		sds = initSigDenseSet();
		FILE *fp = fopen(cluster_filename, "r");
		if(fp == NULL){
			 cout<<"File "<<cluster_filename<< " could not be opened in density function"<<endl;
			 system("pause");
		}

		while(fgets(line, MAXLINE, fp)){

			if (line[strlen(line)-1] == '\n')
			  line[strlen(line)-1] = STREND;
			sscanf (line,"%s %s %s",clusterName,dump,edgesNumber);  //diavazei tin proti grammi tou kathe cluster
			tg=readCluster(fp, edgesNumber);							//(format:#cluster : #edges)
//cout<<"elegxos tou cluster  "<<tg->nodes->label<<endl;
			for(tnode=tg->nodes;tnode!=NULL;tnode=tnode->next){		//ipologismos tou sinolikou degree ton korifon pou apoteloun ton cluster
				for(node=g->nodes;node!=NULL;node=node->next){	//
					if(strcmp(node->label,tnode->label)==0){
						orig_degree+=node->degree;
						break;
					}
				}
			}
//cout<<"exoume kai leme: orig_degree= "<<orig_degree<<"   kai ta in= "<<tg->edgecount<<endl<<(float)tg->edgecount/(float)orig_degree<<endl;
			if((float)(tg->edgecount/(float)orig_degree)>=par_out_in){					//elegxos an einai piknos i oxi o cluster.
				SigDense *sd = new SigDense();		// an nai apothikeuse allios katestrepse
				sd->sg       = tg;
				insertSigDense(sds, sd);
				orig_degree=0;
			}
			else{
				destroyGraph(tg);
				orig_degree=0;
			}
		}
		fclose (fp);
	}
	else if(flag==1){				//den einai i proti methodos pou efarmozetai, opote idi exei dimiourgithei lista sds
		
		for (sd = sds->first->next; sd != NULL; sd=sd->next){

			for(tnode=sd->sg->nodes;tnode!=NULL;tnode=tnode->next){		//ipologismos tou sinolikou degree ton korifon pou apoteloun ton cluster
				for(node=g->nodes;node!=NULL;node=node->next){	//
					if(strcmp(node->label,tnode->label)==0){
						orig_degree+=node->degree;
						break;
					}
				}
			}
			if(sd->sg->nodecount<2 || (float)sd->sg->edgecount/orig_degree<par_out_in){			//elegxos 
				sd->prev->next=sd->next;			// an oxi, parekampse ton. PROSOXI!!dimiourgia skoupidion(den svino)
				if(sd->next!=NULL)
				sd->next->prev=sd->prev;
			}
			orig_degree=0;

		}
	}
	else{
		cout<<"The flag is WRONG in density function"<<endl;
		system("pause");
	}
	return sds;
}
Esempio n. 21
0
int main(int argc, char **argv)
{
    t_vertex *v1, *v2, *v3, *v4, *v5, *v6, *v7, *v8, *v9, *v10;
    t_vertex *w;

    t_edge *e;
    t_graph *graph;
    t_stack stack;
    t_queue queue;

    int V = 0;
    int i = 0;
    int dot = 0;
    int bc = 0;
    int is_directed = FALSE;
    int index;
    int f, v, c, o;

    char *file = NULL;
    char *num_vertices = NULL;


    graph = createGraph(TRUE);

    while ((f = getopt (argc, argv, "odhbf:v:")) != -1)
        switch (f)
        {
        case 'd':
            dot = 1;
            break;
        case 'b':
            bc = 1;
            break;
        case 'o':
            is_directed = TRUE;
            break;
        case 'f':
            file = optarg;
            break;
        case 'h':
            help();
            break;
        case 'v':
            num_vertices = optarg;
            break;
        case '?':
            if (isprint (optopt)) {
                fprintf (stderr, "Unknown option: `-%c'.\n", optopt);
                help();
            }
            else {
                fprintf (stderr,
                         "Invalid option `\\x%x'.\n",
                         optopt);
                help();
            }
            return 1;
        default:
            abort();
        }

    for (index = optind; index < argc; index++)
        printf ("Non-option argument %s\n", argv[index]);


    graph = createGraph(is_directed);

    if (num_vertices != NULL) {
        V = atoi(num_vertices) + 1;
        for (i = 1; i < V; i++)
            addVertex(graph, i);

    }

    if (file != NULL)
        readFromCSV(graph, file);

    if (bc == 1) {
        betweennessCentrality(graph);
        printGraphCB(graph);
    }

    if (dot == 1)
        dumpDotGraph(graph);

    destroyCBData(graph);
    destroyGraph(graph);

    return 0;
}
Esempio n. 22
0
HRESULT videoInputCamera::stopDevice() {

	HRESULT HR = NULL;

	//Stop the callback and free it
	if( (sgCallback) && (pSampleGrabber) )
	{
		//printf("SETUP: freeing Grabber Callback\n");
		pSampleGrabber->SetCallback(NULL, 1);
		sgCallback->Release();
		delete sgCallback;
		sgCallback = NULL;
	}

	//Check to see if the graph is running, if so stop it.
	if( (pMediaControl) )
	{
		HR = pMediaControl->Pause();
		if (FAILED(HR)) printf("ERROR - Could not pause pControl\n");

		HR = pMediaControl->Stop();
		if (FAILED(HR)) printf("ERROR - Could not stop pControl\n");
	}

	//Disconnect filters from capture device
	if( (pInputFilter) ) NukeDownstream(pInputFilter);

	//Release and zero pointers to our filters etc
	if (pDestFilter) { 		//printf("SETUP: freeing Renderer \n");
		pDestFilter->Release();
		pDestFilter = NULL;
	}
	if (pInputFilter) { 		//printf("SETUP: freeing Capture Source \n");
		pInputFilter->Release();
		pInputFilter = NULL;
	}
	if (pGrabberFilter) {		//printf("SETUP: freeing Grabber Filter  \n");
		pGrabberFilter->Release();
		pGrabberFilter = NULL;
	}
	if (pSampleGrabber) {       //printf("SETUP: freeing Grabber  \n");
		pSampleGrabber->Release();
		pSampleGrabber = NULL;
	}
	if (pMediaControl) { 		//printf("SETUP: freeing Control   \n");
		pMediaControl->Release();
		pMediaControl = NULL;
	}
	if (pStreamConfig) { 		//printf("SETUP: freeing Stream  \n");
		pStreamConfig->Release();
		pStreamConfig = NULL;
	}

	if (pAmMediaType) { 		//printf("SETUP: freeing Media Type  \n");
		deleteMediaType(pAmMediaType);
	}

	//Destroy the graph
	if (pGraphBuilder) destroyGraph();

	//Release and zero our capture graph and our main graph
	if (pCaptureGraphBuilder) { 		//printf("SETUP: freeing Capture Graph \n");
		pCaptureGraphBuilder->Release();
		pCaptureGraphBuilder = NULL;
	}
	if (pGraphBuilder) { 			//printf("SETUP: freeing Main Graph \n");
		pGraphBuilder->Release();
		pGraphBuilder = NULL;
	}

	comUnInit();
	return S_OK;
}
Esempio n. 23
0
int main (int argc, char * argv[]) {
  printf("Blackbox tests...\n");

  printf("Test 1: newGraph...");
  //empty graph
  Graph g1a = mkTestGraph(0);
  destroyGraph(g1a);
  //single graph
  Graph g1b = mkTestGraph(1);
  destroyGraph(g1b);
  printf("Passed!\n");

  printf("Test 1a: mkEdge...");
  //zero cost edge
  Edge e1a = mkEdge(0, 1, 0);
  assert(e1a.v == 0);
  assert(e1a.w == 1);
  assert(e1a.weight == 0);
  Edge e1ar = mkEdge(1, 0, 0);
  assert(e1ar.v == 1);
  assert(e1ar.w == 0);
  assert(e1ar.weight == 0);
  //edge
  Edge e1b = mkEdge(1, 5, 10);
  assert(e1b.v == 1);
  assert(e1b.w == 5);
  assert(e1b.weight == 10);
  Edge e1br = mkEdge(5, 1, 10);
  assert(e1br.v == 5);
  assert(e1br.w == 1);
  assert(e1br.weight == 10);
  printf("Passed!\n");
  
  printf("Test 2: insertE...");
  //double graph
  Graph g2 = mkTestGraph(2);
  Edge e2 = mkEdge(0, 1, 12);
  insertE(g2, e2);
  assert(numE(g2) == 1);
  destroyGraph(g2);
  printf("Passed!\n");

  printf("Test 3: isAdjacent...");
  //double graph
  Graph g3a = mkTestGraph(2);
  Edge e3a = {0, 1, 12};
  insertE(g3a, e3a);
  assert(numV(g3a) == 2);
  assert(numE(g3a) == 1);
  assert(isAdjacent(g3a, 0, 1) == 1);
  assert(isAdjacent(g3a, 1, 0) == 1);
  destroyGraph(g3a);

  //graph
  Graph g3b = mkTestGraph(3);
  assert(isAdjacent(g3b, 0, 1) == 1);
  assert(isAdjacent(g3b, 0, 2) == 1);
  assert(isAdjacent(g3b, 0, 3) == 1);
  assert(isAdjacent(g3b, 0, 4) == 1);
  assert(isAdjacent(g3b, 1, 2) == 1);
  assert(isAdjacent(g3b, 2, 3) == 1);
  assert(isAdjacent(g3b, 3, 4) == 1);
  destroyGraph(g3b);
  printf("Passed!\n");

  printf("Test 4: adjacentVertices...");
  Graph g4a = mkTestGraph(2);
  Edge e4a = {0, 1, 12};
  insertE(g4a, e4a);
  Vertex adj4a[2]; //allocate space for max number of vertices
  assert(adjacentVertices(g4a, 0, adj4a) == 1);
  assert(adj4a[0] >= 0);
  assert(adjacentVertices(g4a, 1, adj4a) == 1);
  assert(adj4a[0] >= 0);
  destroyGraph(g4a);
  printf("Passed!\n");

  printf("Test 5: incidentEdges...");
  Graph g5 = mkTestGraph(2);
  Edge e5 = {0, 1, 12};
  insertE(g5, e5);
  Edge edges5[1]; //allocate space for max num of edges
  assert(incidentEdges(g5, 0, edges5) == 1);
  int v5 = edges5[0].v; int w5 = edges5[0].w;
  assert( (v5 == 0 && w5 == 1) || (v5 == 1 && w5 == 0) );
  assert(edges5[0].weight == 12);
  assert(incidentEdges(g5, 1, edges5) == 1);
  v5 = edges5[0].v; w5 = edges5[0].w;
  assert( (v5 == 0 && w5 == 1) || (v5 == 1 && w5 == 0) );
  assert(edges5[0].weight == 12);
  destroyGraph(g5);
  printf("Passed!\n");

  printf("Test 6: edges...");
  Graph g6 = mkTestGraph(2);
  Edge e6 = {0, 1, 12};
  insertE(g6, e6);
  Edge es6[1]; //allocate space for max num of edges
  assert(edges(es6, 1, g6) == 1);
  int v6 = es6[0].v; int w6 = es6[0].w;
  assert( (v6 == 0 && w6 == 1) || (v6 == 1 && w6 == 0) );
  assert(es6[0].weight == 12);
  destroyGraph(g6);
  printf("Passed!\n");

  printf("All Test Passed! You are a Beast!\n");
  
  return EXIT_SUCCESS;
}
Esempio n. 24
0
int main(int argc, char const *argv[]) {
	int running = 1, cost = 0, i, j;
	char input[BUFFER_SIZE], *aft;
	char vertex, dest, option;
	Graph *g = NULL;
	createGraph(&g);

	#ifdef DEV

	insertVertex(g, 'a');
	insertVertex(g, 'b');
	insertVertex(g, 'c');
	insertVertex(g, 'd');
	insertVertex(g, 'e');
	insertVertex(g, 'f');
	insertEdge(g, 'a', 'b', 100);
	insertEdge(g, 'a', 'c', 300);
	insertEdge(g, 'a', 'a', 100);
	insertEdge(g, 'd', 'b', 70);
	insertEdge(g, 'f', 'c', 10);
	insertEdge(g, 'a', 'f', 10);
	insertEdge(g, 'a', 'f', 20);
	insertEdge(g, 'a', 'a', 100);
	displayGraph(g);
	greedySearch(g, 'a');
	destroyGraph(g);
	#else

        while (running) {
                memset(input, 0, BUFFER_SIZE);
                printf("\n1 - inserir vertice\n");
                printf("2 - inserir aresta\n");
                printf("3 - remover vertice\n");
                printf("4 - remover aresta\n");
                printf("5 - imprimir grafo\n");
                printf("6 - Busca Gulosa\n");
                printf("7 - sair\n");
                printf("\n$");

                scanf(" %c", &option);
                switch (option) {
                case '1':
                        printf("Digite um id para o novo no (apenas um caracter)\n");
                        printf(">>");
                        scanf(" %c", &vertex);
                        if (!insertVertex(g, vertex)) {
                                printf("Vertice inserido!\n");
                                printf("Digite os vizinhos (exemplo:b10 c20 d30) obs: caso o valor nao seja indicado o default sera 0\n");
                                getchar();
                                fgets(input, BUFFER_SIZE, stdin);
                                for(i = 0; i < strlen(input); i++) {
                                        if(isalpha(input[i])) {
                                                dest = input[i];
                                                for(j = i+1; j <= strlen(input); j++) {
                                                        if(isdigit(input[j])) {
                                                                cost = strtod(&input[j], &aft);
                                                                i = (aft - input) -1;
                                                                if(!insertEdge(g, vertex, dest, cost))
                                                                        printf("Aresta inserida [%c] - [%c] com custo %d!\n", vertex, dest, cost);
                                                                break;
                                                        }
                                                        if(isalpha(input[j]) || input[j] == '\0') {
                                                                if(!insertEdge(g, vertex, dest, 0))
                                                                        printf("Aresta inserida [%c] - [%c] com custo 0!\n", vertex, dest);
                                                                break;
                                                        }
                                                }
                                        }
                                }
                        }

                        break;
                case '2':
                        printf("Digite um par de vertices e um custo para a nova aresta (exemplo: A B 100)\n");
                        printf(">>");
                        scanf(" %c %c %d", &vertex, &dest, &cost);
                        if(!insertEdge(g, vertex, dest, cost))
                                printf("Aresta inserida!\n");
                        break;
                case '3':
                        printf("Digite o id do vertice a ser deletado\n");
                        printf(">>");
                        scanf(" %c", &vertex);
                        if(!removeVertex(g, vertex))
                                printf("vertice removido\n");
                        break;
                case '4':
                        printf("Digite o par de vertices e o custo da aresta (exemplo: A B 100)\n");
                        printf(">>");
                        scanf(" %c %c %d", &vertex, &dest, &cost);
                        if(!removeEdge(g, vertex, dest, cost))
                                printf("aresta removida!\n");
                        break;
                case '5':
                        displayGraph(g);
                        break;
                case '6':
                        printf("Digite um vertice para inicio da busca\n");
                        printf(">>");
                        scanf(" %c", &vertex);
                        greedySearch(g, vertex);
                        break;

                case '7':
                        printf("Ate logo\n");
                        running = 0;
                        destroyGraph(g);
                        break;
                default:
                        printf("Opcao invalida\n");
                        break;
                }
        }
	#endif
	return 0;
}
Graph * parseInputFile( const char * inputFile )
{
	FILE * fptr = NULL;
	int numUsers;
	float delta1;
	float delta2;
	float alpha;
	int queryId;
	int i = 0;
	Graph * graph1 = NULL;
	Graph * graph2 = NULL;
	User * userList = NULL;
	int id;
	int age;
	int gender;
	int maritalStatus;
	int race;
	int birthPlace;
	int language;
	int occupation;
	int income;

	//	Open file and check if successful
	fptr = fopen( inputFile, "r" );

	if( fptr == NULL )
	{
		printf( "ERROR!\nFile %s could not be opened!\n", inputFile );
		return 0;
	}

	//	Get lines
	fscanf( fptr, "%d,%f,%f,%d,%f", &numUsers, &delta1, &delta2, &queryId, &alpha );

	//	Allocate user List
	userList = malloc( sizeof(User) * numUsers );

	for( i = 0; i < numUsers; i++ )
	{
		//	Parse inputs
		fscanf( fptr, "%d,%d,%d,%d,%d,%d,%d,%d,%d",
				&id,
				&age,
				&gender,
				&maritalStatus,
				&race,
				&birthPlace,
				&language,
				&occupation,
				&income );

		//	Create user instance
		createUser( &userList[i], id, age, gender, maritalStatus, race,
				birthPlace, language, occupation, income );
	}

	//printUserList( userList, numUsers );

	graph1 = createGraph( userList, numUsers, delta1 );
	graph2 = createGraph( userList, numUsers, delta2 );

	/*
	int inputid;
	printf( "Enter user id for friends\n" );
	scanf( "%d", &inputid );
	while( inputid != 0 )
	{
		printFriendList( graph1, &(graph1 -> userList[ inputid - 1 ]) );
		printf( "Enter user id for friends\n" );
		scanf( "%d", &inputid );
	}

	int j;
	for( i = 0; i < numUsers; i ++ )
	{
		for( j = 0; j < numUsers; j++ )
		{
			printRelationBetween( graph1,
			&(graph1 -> userList[i]), &(graph1 -> userList[j]) );
		}
	}
	*/

	//  ~~~~~~~~~~~~~~~~~~~	QUERYS ~~~~~~~~~~~~~~~~~~~

	//	Dense Graph
	printf(  "Dense Graph : \n-------------\n" );
	printf(  "\n** Query1 **\n" );
	getMinLength( graph1, queryId );
	printf(  "\n** Query2 **\n" );
	getAllNode( graph1, queryId, alpha );
	printf(  "\n** Query3 **\n" );
	getFriends( graph1, queryId );
	printf(  "\n** Query4 **\n" );
	getFriendsOfFriends( graph1, queryId );
	printf(  "\n** Query5 **\n" );
	getAvgDegreeOfNode( graph1 );
	printf(  "\n** Query6 **\n" );
	getAvgDegreeOfSecondNode( graph1 );

	//	Sparse Graph
	printf(  "\nSparse Graph : \n-------------\n" );
	printf(  "\n** Query1 **\n" );
	getMinLength( graph2, queryId );
	printf(  "\n** Query2 **\n" );
	getAllNode( graph2, queryId, alpha );
	printf(  "\n** Query3 **\n" );
	getFriends( graph2, queryId );
	printf(  "\n** Query4 **\n" );
	getFriendsOfFriends( graph2, queryId );
	printf(  "\n** Query5 **\n" );
	getAvgDegreeOfNode( graph2 );
	printf(  "\n** Query6 **\n" );
	getAvgDegreeOfSecondNode( graph2 );

	//  ~~~~~~~~~~~~~~~~~~~	CLEAN UP  ~~~~~~~~~~~~~~~~~~~

	destroyUserList( userList );
	destroyGraph( graph1 );
	destroyGraph( graph2 );

	//	Close file
	fclose( fptr );
	return NULL;
}