[Lemon-commits] [lemon_svn] ladanyi: r78 - hugo/trunk/src/work/akos

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:37:11 CET 2006


Author: ladanyi
Date: Wed Feb  4 19:59:07 2004
New Revision: 78

Added:
   hugo/trunk/src/work/akos/
   hugo/trunk/src/work/akos/demo.in
   hugo/trunk/src/work/akos/loader.h
   hugo/trunk/src/work/akos/loader_demo.cc
   hugo/trunk/src/work/akos/makefile

Log:
added the loader for the DIMACS file format


Added: hugo/trunk/src/work/akos/demo.in
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/akos/demo.in	Wed Feb  4 19:59:07 2004
@@ -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

Added: hugo/trunk/src/work/akos/loader.h
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/akos/loader.h	Wed Feb  4 19:59:07 2004
@@ -0,0 +1,41 @@
+#ifndef LOADER_H
+#define LOADER_H
+
+#include <map>
+
+#define LINE_LEN 1024
+
+template<typename Graph>
+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<int, typename Graph::NodeIt> 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

Added: hugo/trunk/src/work/akos/loader_demo.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/akos/loader_demo.cc	Wed Feb  4 19:59:07 2004
@@ -0,0 +1,34 @@
+#include <vector>
+#include <iostream>
+#include <list_graph.hh>
+#include <bfs_iterator.hh>
+#include <loader.h>
+
+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<ListGraph> bfs_test(G, G.first<EachNodeIt>());
+  bfs_test.run();
+  std::cout << "reached: ";
+  for(EachNodeIt i=G.first<EachNodeIt>(); i.valid(); ++i) {
+    std::cout << bfs_test.reached.get(i) << " ";
+  }
+  std::cout<<std::endl;
+  std::cout << "dist: ";
+  for(EachNodeIt i=G.first<EachNodeIt>(); i.valid(); ++i) {
+    std::cout << bfs_test.dist.get(i) << " ";
+  }
+  std::cout<<std::endl;
+}

Added: hugo/trunk/src/work/akos/makefile
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/akos/makefile	Wed Feb  4 19:59:07 2004
@@ -0,0 +1,9 @@
+CXXFLAGS = -g -Wall -ansi -pedantic
+CXX := $(shell type -p g++-3.3 || type -p g++-3.2 || type -p g++-3.0 || type -p g++-3 || echo g++)
+
+loader_demo: loader_demo.cc ../list_graph.hh ../bfs_iterator.hh loader.h
+	$(CXX) $(CXXFLAGS) -I. -I.. loader_demo.cc -o loader_demo 
+clean:
+	$(RM) loader_demo
+
+.PHONY: clean



More information about the Lemon-commits mailing list