Ejemplo n.º 1
0
ParkingLot * InitParkingLot( FILE * mapconfig, int col, int row, int floors, int accesses )
{
    char *** matrix;
    int *vertices, *ramps;
    ParkingLot * parkinglot;

    vertices = (int*)malloc(sizeof(int));
    VerifyMalloc( (Item) vertices );

    ramps = (int*)malloc(sizeof(int));
    VerifyMalloc( (Item) ramps );

    parkinglot = (ParkingLot*) malloc( sizeof(ParkingLot) );
    VerifyMalloc((Item) parkinglot);
    parkinglot->freespots = 0;
    matrix = MatrixInit(vertices, ramps, mapconfig, col, row, floors); /*Creates string cointaining the map - its a 3d string */
    parkinglot->graphdecoder = GraphDecoderInit(matrix, col, row, floors, *vertices, &(parkinglot->freespots) ); /*Creates array cointaining the Decoder for the graph positions*/
    parkinglot->g = GraphInit(*vertices, matrix, parkinglot->graphdecoder, col, row);
    parkinglot->accesseshead = InitAccesses(accesses, parkinglot->graphdecoder, *vertices);
    parkinglot->parkedcarshead = ListInit();
    parkinglot->queuehead = ListInit();

    /**PrintGraph(GetGraph(parkinglot), *vertices); */ /*prints the graph in the parkinglot */
    FreeMatrix(matrix, col, row);
    free(vertices);
    free(ramps);

    return (parkinglot);
}
Ejemplo n.º 2
0
void CGraph::LoadDxfFile(CString dxfFileString)
{
	g_ptrGraphArray.RemoveAll();

	DxfReading(dxfFileString);

	GraphInit();

	PreviewDxfGraph();
}
Ejemplo n.º 3
0
/**
 * @function GUI_Init
 * @brief Initialize the GUI; call me first !
 * @param none
 * @return none
 */
void GUI_Init(void) {

  /*load graphic resources (color LUT for sprites)*/
  GraphInit();

  /*save the current stack address; all data before this address belongs to GraphInit*/
  addrStart = salloc(0);

  /*some macro need a specific init.*/
  GUI_M_KeyboardInit();

  /*delete all & clear screen*/
  //GUI_ClearAll(); /*no, the user does it manually*/
}
Ejemplo n.º 4
0
int main(void){
    ALGraph graph;
    GraphInit(&graph, 5);

    AddEdge(&graph, A, B);
    AddEdge(&graph, A, D);
    AddEdge(&graph, B, C);
    AddEdge(&graph, C, D);
    AddEdge(&graph, D, E);
    AddEdge(&graph, E, A);

    ShowGraphEdgeInfo(&graph);
    GraphDestroy(&graph);
    return 0;

}
Ejemplo n.º 5
0
graphT ReadFileAndBuildGraph(const char *inputFile) {
  FILE *ifp = fopen(inputFile, "r");
  int n, m;
  fscanf(ifp, "%d", &n);
  fscanf(ifp, "%d", &m);
  graphT g = GraphInit(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    fscanf(ifp, "%d %d", &u, &v);
    // Input graphs are indexed from 1 to n and we represent graphs from 
    // 0 to n-1
    --u;
    --v;
    GraphAddEdge(g, u, v);
  }
  fclose(ifp);
  return g;
}
Ejemplo n.º 6
0
Archivo: graf.c Proyecto: jerzro/algi
int main(int argc, char **argv)
{ 
  if( argc > 3 || argc < 2){
    printf("Usage: %s infile [outfile = graph.out]\n", argv[0]);
    return -1;
  }
  int i = 0; // iterator
  char *filename; // nazwa pliku wejsciowego
  int V; int E;
  edge e[100]; // tablica 100 wierzcho³kow
  filename = argv[1];
  GraphImport(filename, e); // wstawienie krawedzi e[] z pliku
  V = e[0].v; E = e[0].w;
  graph g = GraphInit(V);
  for(i = 1; i <= E; i++)
    EdgeIns(g, e[i]);
  GraphShow(g);
  GraphDel(g);
  return 0;
}
Ejemplo n.º 7
0
/***********************3。创建图**********************/
void GraphCreate(GRAPH  *L)
{
	int i, j;
	GraphInit(L);
	printf("请输入顶点数目:");
	scanf("%d", &L->num);
	printf("请输入各顶点的信息(单个符号):");
	for (i = 0; i < L->num; i++)
	{
		fflush(stdin);
		scanf("%c", &L->vexs[i]);
	}
	printf("请输入边权矩阵的信息:");
	for (i = 0; i < L->num; i++)
	{
		for (j = 0; j < L->num; j++)
		{
			scanf("%f", &L->arcs[i][j]);
		}
	}
	printf("图已经创建完毕!");
}
Ejemplo n.º 8
0
//主函数
int main(void)
{
	AdjList *graph;
//	int a[30][30];
	int i = 0;


	graph = (AdjList *)malloc(sizeof(AdjList));
	GraphInit(graph);
//	GraphRead(graph, a);
	GraphListCreat(graph);
//	GraphListDepthSearch(graph, 0);
//	GraphListDepthFind(graph, 1, 4);
/*	while(i < 14){
		GraphListPath_DJS(graph, 0, i);
		i++;
	}*/
	
	GrapgAllWay(graph, 1, 13, weizhi);

	return 0;
}
Ejemplo n.º 9
0
bool CreateTestGraph1(Graph **graphOut){
	GraphCreate(graphOut);

	if(GraphIsDestroyed(*graphOut)){
		logError("fail - CreateTestGraph1() - GraphCreate() returned null.");
		return false;
	}

	size_t numNodes=5;

	/* Create node data */
	char *nodesValues[numNodes];

	for (int i=0; i<numNodes; i++){
		nodesValues[i] = malloc(MAXDATALENGTH);
		snprintf(nodesValues[i],MAXDATALENGTH,"node %d",i);
	}

	/* Create connections with weights. 0 is unconnected.
	 * 0 is connected to 1, 4
	 * 1 is connected to 0, 2, 3
	 * 2 is connected to 1, 3
	 * 3 is connected to 1 ,2 ,4
	 * 4 is connected to 0, 3
	 */

	double adjMatrix [] ={
		0.0, 1.0, 0.0, 0.0, 4.0,
		1.0, 0.0, 5.0, 1.0, 0.0,
		0.0, 5.0, 0.0, 2.0, 0.0,
		0.0, 1.0, 2.0, 0.0, 1.0,
		4.0, 0.0, 0.0, 1.0, 0.0
	};


	if(!GraphInit(*graphOut,(void**) nodesValues, numNodes, adjMatrix)){
		logError("fail - CreateTestGraph1() - GraphInit() was not successful.");
		return false;
	}

	/*
	char *expected =
			"Graph(5):\n"
			"Node(node 4): node 3, node 0\n"
			"Node(node 3): node 4, node 1, node 2\n"
			"Node(node 2): node 3, node 1\n"
			"Node(node 1): node 3, node 0, node 2\n"
			"Node(node 0): node 1, node 4\n";

	const char *result = GraphToString(*graphOut);

	if(strncmp(expected,result,strlen(expected)) != 0){
		logError("fail - GraphToString() did not return expected output: \nexpected:%s\nresult:%s\n",expected,result);
		return false;
	}


	free(result);

	logInfo(ListToString((*graphOut)->edges));
	*/

	return true;
}