main() { int goukei,ninzuu[8],heikin,i; goukei = 0; for (i=0;i<8;i++) { printf("%d時の来店者数を入力してください : ",i); scanf("%d",&ninzuu[i]); } for (i=0;i<8;i++) { goukei += ninzuu[i]; } heikin = goukei / i; printf("一日の平均は%d人です。\n",heikin); initGraph(); for(i=0;i<8;i++) { fillRectangle(i*10,479,i*10+40,479-ninzuu[i],BLACK); } waitButtonPress(); closeGraph(); }
int main(void) { int node_num, edge_num, source; struct Graph graph; time = 0; source = 1; while (scanf("%d %d", &node_num, &edge_num) != EOF) { initGraph(&graph, node_num); input(&graph, edge_num); printf("source node of dfs and bfs is %d:\n", source); printf("depth first search:\n"); for (source = 1; source <= graph.node_num; source++) dfs(&graph, source, visitNode); clearVisit(&graph); printf("breadth first search:\n"); for (source = 1; source <= graph.node_num; source++) bfs(&graph, source); clearVisit(&graph); printf("traverse by topological order:\n"); topos(&graph); deleteEdge(&graph); } return 0; }
int main() { Graph graph; initGraph(&graph); char input[100]; //read console input and build graph while (1) { if (fgets(input, 100, stdin)) { //fgets returns NULL at EOF (EOF in VS cmd line: enter ctrl+z enter) buildGraphFromInput(input, &graph); } else break; } //debug only buildGraphFromInput("A-BD\n", &graph); buildGraphFromInput("B-AC\n", &graph); buildGraphFromInput("C-BG\n", &graph); buildGraphFromInput("D-AEF\n", &graph); buildGraphFromInput("E-DG\n", &graph); buildGraphFromInput("F-D\n", &graph); buildGraphFromInput("G-CE\n", &graph); //traverse graph with BFS breadthFirstSearch(&graph); printf("\n"); return EXIT_SUCCESS; }
MainController::MainController() { width = 880; height = 520; // Init MainWindow and set the data mainWindow = new MainWindow(); mainWindow->setController(this); // Init the graph graph = std::make_shared<Graph>(mainWindow); initGraph(); // Init the units initUnits(); // Set the graph and the units mainWindow->setGraph(graph); mainWindow->setUnits(std::shared_ptr<Cow>(cow), std::shared_ptr<Chicken>(chicken)); mainWindow->resize(width, height); mainWindow->show(); gameLoop = std::unique_ptr<std::thread>(new std::thread(&MainController::run, this)); }
int main(int argc, char **agv) { int i; int visited[SIZE]; Graph *graph = initGraph(SIZE); printf("%d\n", sizeof(int **)); graph->edgeMat[0][1] = 1; graph->edgeMat[0][2] = 1; graph->edgeMat[1][2] = 1; graph->edgeMat[2][0] = 1; graph->edgeMat[2][3] = 1; graph->edgeMat[3][3] = 1; for(i = 0; i < graph->V; i++) { visited[i] = 0; } printf("DFS rec "); depthFirstSearch(graph, visited, 2); for(i = 0; i < graph->V; i++) { visited[i] = 0; } printf("\n DFS non_rec "); depthFirstSearchNonRec(graph, visited, 2); printf("\n BFS non_rec"); breadthFirstSearch(graph, 2); releaseGraph(graph); return 0; }
void doBFS(GraphRef g, int source){ ListRef list = newList(); initGraph(g); insertAfterLast(list, source); g->color[source]= 1; g->distance[source]=0; while(!isEmpty(list)){ int current = getFirst(list); if(current > g->numVertices){ deleteFirst(list); break; } ListRef edgeList = g->vertices[current]; moveFirst(edgeList); while(!offEnd(edgeList)){ int edge = getCurrent(edgeList); if(g->color[edge]==0){ g->distance[edge] = g->distance[current]+1; g->color[edge] = 1; g->parent[edge] = current; insertAfterLast(list, edge); } moveNext(edgeList); } deleteFirst(list); g->color[current] = 2; } makeEmpty(list); freeList(list); }
int main(void) { int node_num, edge_num; struct Matrix_Graph mat_graph; struct Point_Graph poi_graph; while (scanf("%d %d", &node_num, &edge_num) != EOF) { initGraph(&mat_graph, &poi_graph, node_num); input(&mat_graph, &poi_graph, edge_num); printf("matrix multiplication:\n"); matrix_mult(&mat_graph); output(&mat_graph); clearChoose(&mat_graph, &poi_graph); printf("floyd warshall:\n"); floyd_warshall(&mat_graph); output(&mat_graph); clearChoose(&mat_graph, &poi_graph); printf("johnson:\n"); johnson(&mat_graph, &poi_graph); output(&mat_graph); clearEdge(&poi_graph); } return 0; }
task main(){ calibrateLight(); calibrateCompass(); ExploreStack stack; Graph graph; initStack(stack); initGraph(graph); Stub stub; Edge lastEdge; int currentNode = -1; int canNode = -1; //go to node currentNode = exploreNewNode(graph, stack, currentNode, lastEdge); if(detectCan()) { canNode = currentNode; announceCan(currentNode); } //while not empty while(!empty(stack)){ pop(stack, stub); motor[left] = 0; motor[right] = 0; goToNode(graph, currentNode, stub.node); currentNode = stub.node; turnToAngle(stub.angle, 15); turnToLine(); nxtDisplayCenteredTextLine(4, "Exploring..."); int stackSize = stack.top; FollowSegmentTilEnd(lastEdge); currentNode = exploreNewNode(graph, stack, currentNode, lastEdge); if(stackSize == stack.top && detectCan()) { canNode = currentNode; announceCan(currentNode); } } motor[left] = 0; motor[right] = 0; eraseDisplay(); nxtDisplayCenteredTextLine(3, "%i nodes found", graph.nNodes); wait10Msec(500); if(canNode >= 0) { goToNode(graph, currentNode, canNode); motor[left] = 0; motor[right] = 0; eraseDisplay(); nxtDisplayCenteredTextLine(3, "Can was here"); wait10Msec(500); } else { motor[left] = 0; motor[right] = 0; eraseDisplay(); PlaySound(soundLowBuzz); nxtDisplayCenteredTextLine(3, "There was no can"); wait10Msec(500); } }
int main() { int ver = 8; graph *g; g = initGraph(ver); addEdge(g, 0, 7); addEdge(g, 0, 4); addEdge(g, 1, 3); addEdge(g, 1, 2); addEdge(g, 2, 1); addEdge(g, 2, 3); addEdge(g, 3, 0); addEdge(g, 3, 4); addEdge(g, 4, 5); addEdge(g, 5, 7); addEdge(g, 6, 5); addEdge(g, 7, 6); addEdge(g, 7, 4); printGraph(g); dfsinit(g, 2); printGraph(g); }
void LineGraphWidget::resizeEvent(QResizeEvent * e) { if (e->oldSize() != size()) { initGraph(); } }
Graph::Graph(void) { clock_t time=clock(); initGraph(); time=clock()-time; cout<<"creat Graph use time : "<<time<<endl; }
int main(){ int size_g, size_edg, source, target, cost; scanf("%d%d", &size_g, &size_edg); if(size_g < 1 || size_edg < 1) return -1; heap *root = heapCreateRoot(); vertex *vertices = (vertex*)calloc(size_g, sizeof(vertex)); edge **inv = (edge**)calloc(size_g, sizeof(edge*)); initGraph(vertices, size_g); vertices[0].heap_node.key = 0; heapInsert(root, &(vertices[0].heap_node)); while(scanf("%d%d%d", &source, &target, &cost) != EOF) { inserir(vertices, inv, root, size_g, source, target, cost); } g_print_graph(vertices, size_g); freeGraph(vertices, size_g); freeInv(inv, size_g); free(vertices); free(inv); free(root); return 0; }
int main(void) { int node_num, edge_num; double ans; struct Graph graph; while (scanf("%d %d", &node_num, &edge_num) != EOF) { initGraph(&graph, node_num); input(&graph, edge_num); printf("Boruvka:\n"); ans = boruvka(&graph); printf("the MST weigths %2.1f\n", ans); clearChoosedEdge(&graph); printf("kruskal:\n"); ans = kruskal(&graph); printf("the MST weights %.2lf\n", ans); clearChoosedEdge(&graph); printf("prim:\n"); ans = prim(&graph); printf("the MST weights %.2lf\n", ans); deleteEdge(&graph); } return 0; }
Map::Map(string filename, StatsPanel* statsPanel){ //for saved games this->statsPanel=statsPanel; loadSavedFile(filename); showBuildingMoney(); initGraph(); this->statsPanel->showTarget(targets[level]); }
// Copy Function void ClusterGraph::shallowCopy(const ClusterGraph &C) { const Graph &G = C; m_pGraph = &G; m_nClusters = 0; //m_clusterDepth.init(*this, 0); initGraph(G); m_updateDepth = C.m_updateDepth; m_depthUpToDate = C.m_depthUpToDate; // Construct cluster tree ClusterArray<cluster> originalClusterTable(C); cluster c = 0; forall_clusters(c,C) { if (c == C.m_rootCluster) { originalClusterTable[c] = m_rootCluster; //does not really need to be assigned HERE in for m_rootCluster->depth() = 1; OGDF_ASSERT(C.rootCluster()->depth() == 1) continue; } originalClusterTable[c] = newCluster(); originalClusterTable[c]->depth() = c->depth(); }
void EdmondMatching::solveEdmondMatching() { // they've already called addEdge() for all edges // interface with C library assert(graphSize < MAX); initGraph(graphSize); //Since C++ arrays are 0..n-1 and input 1..n , subtractions for (unsigned i=0; i<Edges.size(); i++){ //are made for better memory usage. //scanf(" %d %d",&a,&b); unsigned a = Edges.at(i).first; unsigned b = Edges.at(i).second; //printf("edge: %d %d\n",a,b); if (a!=b) { g[a-1][b-1]=g[b-1][a-1]=unmatched; } } findMaximumMatching(graphSize); for (unsigned i=0; i<graphSize; i++){ for (unsigned j=i+1; j<graphSize; j++) { if (g[i][j]==matched) { Matches.push_back(EdgeType(i+1,j+1)); //printf("match: %d %d\n",i+1,j+1); } } } }
int main() { int ver = 9; graph *g; g = initGraph(ver); addEdge(g, 0, 2); addEdge(g, 0, 3); addEdge(g, 1, 3); addEdge(g, 1, 4); addEdge(g, 2, 3); addEdge(g, 2, 5); addEdge(g, 2, 7); addEdge(g, 3, 4); addEdge(g, 4, 6); addEdge(g, 4, 8); addEdge(g, 5, 6); addEdge(g, 7, 8); printGraph(g); topoSort(g); }
int main() { input(); initGraph(); floyed(); output(); return 0; }
ChartWidget::ChartWidget(QWidget *parent) : QWidget(parent) { initGraph(); QVBoxLayout * vLayout = new QVBoxLayout; vLayout->addWidget(plot); setMinimumSize(400,350); setLayout(vLayout); }
smart_plot::smart_plot(QWidget *parent) : QMainWindow(parent) { myUrlHandler *myHandler = new myUrlHandler(); QDesktopServices::setUrlHandler("file", myHandler, "files"); connect(myHandler, SIGNAL(openFile(const QString&)), this, SLOT( iosOpen(const QString &))); setWindowTitle(tr("Smartplot Ver 2.02.001")); QCoreApplication::setOrganizationName("bgodding"); QCoreApplication::setApplicationName("smartplot"); this->setMinimumSize(320,240); this->resize(1024, 600); this->installEventFilter(this); plots.append(new QCustomPlot(this)); //Setup the main menu QMenu *fileMenu = menuBar()->addMenu(tr("&File")); //Data Handlers: Add menu calls here csvHandler.addToSystemMenu(fileMenu, activePlot()); gitClocHandler.addToSystemMenu(fileMenu, activePlot()); //influxdbHandler.addToSystemMenu(fileMenu, activePlot()); fileMenu->addSeparator(); fileMenu->addAction( QIcon(":/graphics/savePlot.png"), tr("&SaveImage"), this, SLOT(savePlotAsImage()) ); activePlot()->setOpenGl(true,16); setCentralWidget(activePlot()); initGraph(activePlot()); initLegend(activePlot()); #ifdef MOBILE setAttribute( Qt::WA_AcceptTouchEvents ); grabGesture( Qt::TapAndHoldGesture ); // //TODO: Only use these on mobile in lou of pinch to zoom on crappy hardware? QPushButton *zoomIn = new QPushButton("+", this); zoomIn->setObjectName("+"); connect(zoomIn, SIGNAL(released()), this, SLOT(zoomInButtonPressed())); QPushButton *zoomOut = new QPushButton("-", this); zoomOut->setObjectName("-"); connect(zoomOut, SIGNAL(released()), this, SLOT(zoomOutButtonPressed())); #endif contextMenu = new QMenu(this); this->installEventFilter(this); }
int readGraph(){ int n,e,a,b; scanf(" %d %d",&n,&e); //The graph is read and its edges are unmatched by default. initGraph(n); //Since C++ arrays are 0..n-1 and input 1..n , subtractions for (int i=0; i<e; i++){ //are made for better memory usage. scanf(" %d %d",&a,&b); if (a!=b) g[a-1][b-1]=g[b-1][a-1]=unmatched; } return n; }
void GrabCut::fitGMMs() { // Step 3: Build GMMs using Orchard-Bouman clustering algorithm buildGMMs(*m_backgroundGMM, *m_foregroundGMM, *m_GMMcomponent, *m_image, *m_hardSegmentation); // Initialize the graph for graphcut (do this here so that the T-Link debugging image will be initialized) initGraph(); // Build debugging images buildImages(); }
void main () { G *g = initGraph (6); addEdge(g, 5, 2); addEdge(g, 5, 0); addEdge(g, 4, 0); addEdge(g, 4, 1); addEdge(g, 2, 3); addEdge(g, 3, 1); topSort(g); }
// Construction of a new cluster graph. All nodes // are children of the root cluster ClusterGraph::ClusterGraph(const Graph &G) : GraphObserver(&G), m_pGraph(&G), m_clusterIdCount(0), m_postOrderStart(0), m_rootCluster(0), m_allowEmptyClusters(1), m_updateDepth(false), m_depthUpToDate(false) { m_nClusters = 0; m_lcaNumber = 0; m_clusterArrayTableSize = G.nextPower2(MIN_CLUSTER_TABLE_SIZE, G.nodeArrayTableSize()); //m_clusterDepth.init(*this, 0); initGraph(G); }
/** * Map constructor taking a filename, a link to the statistics and a role */ Map::Map(string filename, StatsPanel* statsPanel, int role, string accountID){ // for new games this->filename=filename; this->role=role; this->statsPanel=statsPanel; this->accountID=accountID; loadFile(filename); showBuildingMoney(); initGraph(); if(role==0) level=0; else level=targets.size()-1; this->statsPanel->showTarget(targets[level]); }
// Construction of a new cluster graph. All nodes // are children of the root cluster void ClusterGraph::init(const Graph &G) { clear(); m_clusterIdCount = 0; m_postOrderStart = 0; m_pGraph = &G; m_nClusters = 0; m_lcaNumber = 0; m_clusterArrayTableSize = G.nextPower2(MIN_CLUSTER_TABLE_SIZE, G.nodeArrayTableSize()); //m_clusterDepth.init(*this, 0); initGraph(G); }
void QBSoundMac::startAUGraph() { //printf("startAUGraph\n"); if (!mOpenGraph) { if (!mInitGraph) { initGraph(); mInitGraph = true; } AUGraphStop(mGraph); AUGraphStart(mGraph); } mOpenGraph = true; }
/** * Reads the graph from the given file, and fills the arrays of source and dest vertices * Each edge in the graph is represented by (srcVerts[i], destVerts[i]) */ Graph * parseGraphFile(char* filename) { int n, m; int *srcVerts, *destVerts; FILE *file = fopen(filename, "r"); Graph *graph; if(file != NULL) { char line[1000]; int lineNum = 0, vertIndex = 0; while(fgets(line, sizeof line, file) != NULL) { // Strip the trailing new line character size_t ln = strlen(line) - 1; if(line[ln] == '\n') { line[ln] = '\0'; } if(lineNum == 0) { // First line, get n and m values char *tok = strtok(line, " "); n = strtol(tok, NULL, 10); tok = strtok(NULL, " "); m = strtol(tok, NULL, 10); // Initialise srcVerts and destVerts to number of edges srcVerts = (int *) malloc(sizeof(int) * m); destVerts = (int *) malloc(sizeof(int) * m); } else { // Edge definition, put into src and dest arrays char *tok = strtok(line, " "); int src = strtol(tok, NULL, 10); srcVerts[vertIndex] = src; tok = strtok(NULL, " "); int dest = strtol(tok, NULL, 10); destVerts[vertIndex] = dest; vertIndex++; } lineNum++; } // Generate the graph with the edges from the file graph = initGraph(n, m, srcVerts, destVerts); free(srcVerts); free(destVerts); } fclose(file); return graph; }
void inputGraph () { int e, v; printf("Enter the number of vertices: "); scanf(" %d", &v); printf("Enter the number of edges: "); scanf(" %d", &e); initGraph(v, e); int s, d, w, ch = 0; do { printf("Enter edge details (Src, Dst, Wt): "); scanf(" %d %d %d", &s, &d, &w); addEdge(s-1, d-1, w); ch++; } while (ch < e); }
main(void) { int i; int array[10] = {10,102,20,50,64,0,85,50,12,10}; initGraph(); for(i=0;i<10;i++) { fillRectangle(i*10,479,i*10+40,479-array[i],BLACK); } waitButtonPress(); closeGraph(); }