# HG changeset patch # User ladanyi # Date 1075921147 0 # Node ID 8a39e8b9cdd78cc605104b81dc7b986320ef8d0b # Parent aa1700f78754fc51325c0220c218fff93742b404 added the loader for the DIMACS file format diff -r aa1700f78754 -r 8a39e8b9cdd7 src/work/akos/demo.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/akos/demo.in Wed Feb 04 18:59:07 2004 +0000 @@ -0,0 +1,17 @@ +c +c This is a simple example file to demonstrate the +c DIMACS input file format for minimum-cost flow problems. +c +c problem line : +p min 4 5 +c +c node descriptor lines : +n 1 4 +n 4 -4 +c +c arc descriptor lines : +a 1 2 0 4 2 +a 1 3 0 2 2 +a 2 3 0 2 1 +a 2 4 0 3 3 +a 3 4 0 5 1 diff -r aa1700f78754 -r 8a39e8b9cdd7 src/work/akos/loader.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/akos/loader.h Wed Feb 04 18:59:07 2004 +0000 @@ -0,0 +1,41 @@ +#ifndef LOADER_H +#define LOADER_H + +#include + +#define LINE_LEN 1024 + +template +void LoadGraph(Graph &G, char *filename) { + FILE *file; + if ((file = fopen(filename, "r")) == NULL) { + printf("Could not open %s\n", filename); + return; + } + int i, n1, n2; + std::map nmap; + char line[LINE_LEN]; + while (fgets(line, LINE_LEN, file)) { + switch (line[0]) { + case 'n': + nmap[atoi(line + 1)] = G.addNode(); + break; + case 'a': + n1 = atoi(line + 1); + i = 1; + while (isspace(line[i])) i++; + while (isdigit(line[i])) i++; + n2 = atoi(line + i); + if (nmap.find(n1) == nmap.end()) { + nmap[n1] = G.addNode(); + } + if (nmap.find(n2) == nmap.end()) { + nmap[n2] = G.addNode(); + } + G.addEdge(nmap[n1], nmap[n2]); + break; + } + } +} + +#endif diff -r aa1700f78754 -r 8a39e8b9cdd7 src/work/akos/loader_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/akos/loader_demo.cc Wed Feb 04 18:59:07 2004 +0000 @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include + +using namespace marci; + +int main(int, char **) { + typedef ListGraph::NodeIt NodeIt; + typedef ListGraph::EdgeIt EdgeIt; + typedef ListGraph::EachNodeIt EachNodeIt; + typedef ListGraph::EachEdgeIt EachEdgeIt; + typedef ListGraph::OutEdgeIt OutEdgeIt; + typedef ListGraph::InEdgeIt InEdgeIt; + typedef ListGraph::SymEdgeIt SymEdgeIt; + + ListGraph G; + LoadGraph(G, "demo.in"); + + std::cout << "bfs from the first node" << std::endl; + bfs bfs_test(G, G.first()); + bfs_test.run(); + std::cout << "reached: "; + for(EachNodeIt i=G.first(); i.valid(); ++i) { + std::cout << bfs_test.reached.get(i) << " "; + } + std::cout<(); i.valid(); ++i) { + std::cout << bfs_test.dist.get(i) << " "; + } + std::cout<