diff --git a/MSVC/INDDGO.sln b/MSVC/INDDGO.sln
index 3d531f8..0567014 100755
--- a/MSVC/INDDGO.sln
+++ b/MSVC/INDDGO.sln
@@ -11,10 +11,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "serial_wis", "serial_wis\se
{E88CD5F0-B70E-4504-B83B-393FC3FC12BD} = {E88CD5F0-B70E-4504-B83B-393FC3FC12BD}
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "complement", "complement\complement.vcxproj", "{5C254779-B077-4F58-8105-FC27A27074F6}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gen_pkt", "gen_pkt\gen_pkt.vcxproj", "{7445D331-FCBB-4477-B3F4-576B3A435505}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -33,14 +29,6 @@ Global
{F0033BB8-C99B-4696-9350-F6B97850C220}.Debug|Win32.Build.0 = Debug|Win32
{F0033BB8-C99B-4696-9350-F6B97850C220}.Release|Win32.ActiveCfg = Release|Win32
{F0033BB8-C99B-4696-9350-F6B97850C220}.Release|Win32.Build.0 = Release|Win32
- {5C254779-B077-4F58-8105-FC27A27074F6}.Debug|Win32.ActiveCfg = Debug|Win32
- {5C254779-B077-4F58-8105-FC27A27074F6}.Debug|Win32.Build.0 = Debug|Win32
- {5C254779-B077-4F58-8105-FC27A27074F6}.Release|Win32.ActiveCfg = Release|Win32
- {5C254779-B077-4F58-8105-FC27A27074F6}.Release|Win32.Build.0 = Release|Win32
- {7445D331-FCBB-4477-B3F4-576B3A435505}.Debug|Win32.ActiveCfg = Debug|Win32
- {7445D331-FCBB-4477-B3F4-576B3A435505}.Debug|Win32.Build.0 = Debug|Win32
- {7445D331-FCBB-4477-B3F4-576B3A435505}.Release|Win32.ActiveCfg = Release|Win32
- {7445D331-FCBB-4477-B3F4-576B3A435505}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/MSVC/INDDGO.suo b/MSVC/INDDGO.suo
index cb4e48b..1ea1688 100755
Binary files a/MSVC/INDDGO.suo and b/MSVC/INDDGO.suo differ
diff --git a/MSVC/complement/complement.vcxproj b/MSVC/complement/complement.vcxproj
deleted file mode 100755
index ef32a07..0000000
--- a/MSVC/complement/complement.vcxproj
+++ /dev/null
@@ -1,88 +0,0 @@
-
-
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
-
-
-
-
- {5C254779-B077-4F58-8105-FC27A27074F6}
- Win32Proj
- metis502
-
-
-
- Application
- true
- Unicode
-
-
- Application
- false
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
-
- false
-
-
-
-
-
- Level3
- Disabled
- HAS_GMP;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- ../../../mpir-2.5.2;../../max_wis/inc;../../../uthash-1.9.5/src/;../../lib_graphd/inc/;../../lib_treed/inc/;%(AdditionalIncludeDirectories)
-
-
- Console
- true
- ../$(Configuration);../../../mpir-2.5.2/build.vc10/Win32/$(Configuration)
- lib_graphd.lib;lib_treed.lib;mpir.lib;%(AdditionalDependencies)
-
-
-
-
- Level3
-
-
- MaxSpeed
- true
- true
- _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- ../../../mpir-2.5.2;../../max_wis/inc;../../../uthash-1.9.7/;../../lib_graphd/inc/;../../lib_treed/inc/;../../util/inc
-
-
- Console
- true
- true
- true
- ../$(Configuration);../../../mpir-2.5.2/build.vc10/Win32/$(Configuration)
- lib_graphd.lib;lib_treed.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MSVC/complement/complement.vcxproj.filters b/MSVC/complement/complement.vcxproj.filters
deleted file mode 100755
index 9c847d0..0000000
--- a/MSVC/complement/complement.vcxproj.filters
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hpp;hxx;hm;inl;inc;xsd
-
-
- {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
- rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
-
-
- Source Files
-
-
-
\ No newline at end of file
diff --git a/MSVC/gen_pkt/gen_pkt.vcxproj b/MSVC/gen_pkt/gen_pkt.vcxproj
deleted file mode 100755
index 53b19fe..0000000
--- a/MSVC/gen_pkt/gen_pkt.vcxproj
+++ /dev/null
@@ -1,88 +0,0 @@
-
-
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
-
-
-
-
- {7445D331-FCBB-4477-B3F4-576B3A435505}
- Win32Proj
- metis502
-
-
-
- Application
- true
- Unicode
-
-
- Application
- false
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
-
- false
-
-
-
-
-
- Level3
- Disabled
- HAS_GMP;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- ../../../mpir-2.5.2;../../max_wis/inc;../../../uthash-1.9.5/src/;../../lib_graphd/inc/;../../lib_treed/inc/;%(AdditionalIncludeDirectories)
-
-
- Console
- true
- ../$(Configuration);../../../mpir-2.5.2/build.vc10/Win32/$(Configuration)
- lib_graphd.lib;lib_treed.lib;mpir.lib;%(AdditionalDependencies)
-
-
-
-
- Level3
-
-
- MaxSpeed
- true
- true
- _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- ../../../mpir-2.5.2;../../max_wis/inc;../../../uthash-1.9.7/;../../lib_graphd/inc/;../../lib_treed/inc/;../../util/inc
-
-
- Console
- true
- true
- true
- ../$(Configuration);../../../mpir-2.5.2/build.vc10/Win32/$(Configuration)
- lib_graphd.lib;lib_treed.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
-
-
-
-
-
-
\ No newline at end of file
diff --git a/MSVC/gen_pkt/gen_pkt.vcxproj.filters b/MSVC/gen_pkt/gen_pkt.vcxproj.filters
deleted file mode 100755
index 5c9925d..0000000
--- a/MSVC/gen_pkt/gen_pkt.vcxproj.filters
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hpp;hxx;hm;inl;inc;xsd
-
-
- {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
- rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
-
-
- Source Files
-
-
-
\ No newline at end of file
diff --git a/MSVC/lib_graphd/lib_graphd.vcxproj b/MSVC/lib_graphd/lib_graphd.vcxproj
index b395727..4c45626 100755
--- a/MSVC/lib_graphd/lib_graphd.vcxproj
+++ b/MSVC/lib_graphd/lib_graphd.vcxproj
@@ -11,7 +11,11 @@
+
+
+
+
@@ -19,13 +23,19 @@
+
+
+
+
+
-
+
+
{BFE092BE-DF45-44F1-B013-A98820441A40}
diff --git a/MSVC/lib_graphd/lib_graphd.vcxproj.filters b/MSVC/lib_graphd/lib_graphd.vcxproj.filters
index acec539..54e063c 100755
--- a/MSVC/lib_graphd/lib_graphd.vcxproj.filters
+++ b/MSVC/lib_graphd/lib_graphd.vcxproj.filters
@@ -15,9 +15,21 @@
+
+ Source Files
+
+
+ Source Files
+
Source Files
+
+ Source Files
+
+
+ Source Files
+
Source Files
@@ -39,15 +51,30 @@
Source Files
+
+ Source Files
+
Source Files
+
+ Source Files
+
Source Files
Source Files
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
Source Files
@@ -57,7 +84,10 @@
Source Files
-
+
+ Source Files
+
+
Source Files
diff --git a/lib_graphd/inc/Graph.h b/lib_graphd/inc/Graph.h
index 90ee634..c259e99 100644
--- a/lib_graphd/inc/Graph.h
+++ b/lib_graphd/inc/Graph.h
@@ -25,8 +25,10 @@
#ifdef _OPENMP
#include
#else
- #define omp_get_num_threads() 0
- #define omp_get_thread_num() 0
+ #ifndef HAS_METIS
+ #define omp_get_num_threads() 1
+ #define omp_get_thread_num() 0
+ #endif
#endif
#include "GraphInterface.h"
diff --git a/lib_graphd/inc/GraphCreator.h b/lib_graphd/inc/GraphCreator.h
index 3984e07..e6cfd0b 100644
--- a/lib_graphd/inc/GraphCreator.h
+++ b/lib_graphd/inc/GraphCreator.h
@@ -33,6 +33,9 @@ namespace Graph {
public:
virtual VertexWeightedGraph *create_random_edge_subgraph(VertexWeightedGraph *wmg, int percent_edges);
virtual VertexWeightedGraph *initialize_ktree(int n, int tw);
+ virtual Graph *initialize_rig(int n, int seed, list *probs);
+ virtual Graph *initialize_rmat(int l, int m, double *probs, int seed, bool self_loop);
+
// Creates the induced subgraph on the given list of vertices (by position in adj_list).
// Does not check connectedness. Caller must allocate space for the graph G.
virtual VertexWeightedGraph *create_induced_subgraph(VertexWeightedGraph *wmg, list *members, bool make_simple);
diff --git a/lib_graphd/inc/GraphReader.h b/lib_graphd/inc/GraphReader.h
index 61d2a7b..1cb72f7 100644
--- a/lib_graphd/inc/GraphReader.h
+++ b/lib_graphd/inc/GraphReader.h
@@ -28,9 +28,7 @@
#include "Log.h"
#include "Debug.h"
#include
-#if !WIN32 && !WIN64
#include
-#endif
#include
#include
#include
diff --git a/lib_graphd/inc/GraphWriter.h b/lib_graphd/inc/GraphWriter.h
index d0764d8..92e41e8 100644
--- a/lib_graphd/inc/GraphWriter.h
+++ b/lib_graphd/inc/GraphWriter.h
@@ -28,9 +28,7 @@
#include "Log.h"
#include "Debug.h"
#include
-#if !WIN32 && !WIN64
#include
-#endif
#include
#include
#include
diff --git a/lib_graphd/inc/RndNumGen.h b/lib_graphd/inc/RndNumGen.h
index 6fc9686..9ccee69 100644
--- a/lib_graphd/inc/RndNumGen.h
+++ b/lib_graphd/inc/RndNumGen.h
@@ -23,6 +23,7 @@
#define RNDNUMGEN_H_
namespace Graph {
+ void init_lcgrand(int stream, int seed);
double lcgrand(int stream);
void random_permutation(int *perm, int n);
int rand_int(int min, int max);
diff --git a/lib_graphd/src/AdjMatrixGraphReader.cpp b/lib_graphd/src/AdjMatrixGraphReader.cpp
new file mode 100644
index 0000000..a91fbca
--- /dev/null
+++ b/lib_graphd/src/AdjMatrixGraphReader.cpp
@@ -0,0 +1,127 @@
+/*
+ This file is part of INDDGO.
+
+ Copyright (C) 2012, Oak Ridge National Laboratory
+
+ This product includes software produced by UT-Battelle, LLC under Contract No.
+ DE-AC05-00OR22725 with the Department of Energy.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the New BSD 3-clause software license (LICENSE).
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ LICENSE for more details.
+
+ For more information please contact the INDDGO developers at:
+ inddgo-info@googlegroups.com
+
+ */
+
+#include "AdjMatrixGraphReader.h"
+#include "Debug.h"
+#include
+
+namespace Graph {
+ AdjMatrixGraphReader::AdjMatrixGraphReader(){
+ }
+
+ AdjMatrixGraphReader::~AdjMatrixGraphReader(){
+ }
+
+ /**
+ * Reads the file and populates the Graph data fields.
+ * Ignores any self-loop edges.
+ * If an error is found, some hopefully relevant information is printed to
+ * stderr.
+ * The symmetric flag should be true if you want symmetric adjacency lists and false for anti_symmetric ones.
+ */
+ void AdjMatrixGraphReader::read_graph(const char *mat_file){
+ int i, j, k, m, n, retval;
+ FILE *in;
+
+ if((in = fopen(mat_file, "r")) == NULL){
+ fatal_error("%s: Error opening %s for reading\n", __FUNCTION__,
+ mat_file);
+ }
+
+ fscanf(in, "%d\n", &n);
+ //printf("%s: Graph has %d nodes\n", __FUNCTION__, n);
+ // Each row will have n binary entries, and there will be n rows.
+ this->degree.resize(n, 0);
+ this->nodes.resize(n);
+ this->capacity = n;
+ i = 0; // Use i to keep track of row
+ m = 0; // To count edges
+ while(!feof(in)){
+ if(i >= n){
+ break;
+ }
+ for(k = 0; k < n; k++){
+ retval = fscanf(in, "%d ", &j);
+ //printf("%s: Read in %d\n", __FUNCTION__, j);
+ if(retval != 1){
+ fatal_error("Didn't read digit properly from matrix\n");
+ }
+ if((j != 0) && (j != 1) ){
+ fatal_error("%s: Encountered entry %d!=0 or 1!\n",
+ __FUNCTION__, j);
+ }
+ if(j == 1){
+ //ignore self loops!
+ if(i != k){
+ nodes[i].add_nbr(k);
+ degree[i]++;
+ m++;
+ }
+ }
+ }
+ // Set 1-based labels?
+ nodes[i].set_label(i + 1);
+ // Advance to next row
+ i++;
+ }
+ fclose(in);
+
+ this->num_nodes = n;
+ if(2 * (m / 2) != m){
+ fatal_error(
+ "%s: Found an odd number of ones (%d). Non-symmetric matrix. Please correct.\n",
+ __FUNCTION__, m);
+ }
+ this->num_edges = m / 2; // Assume we were given a symmetric matrix!!
+ this->capacity = n;
+
+ for(i = 0; i < this->capacity; i++){
+ if(nodes[i].get_label() == -1){
+ nodes[i].set_label(i + 1);
+ }
+ }
+
+ return;
+ } // read_graph
+
+ vector AdjMatrixGraphReader::get_degree(){
+ return degree;
+ }
+
+ vector AdjMatrixGraphReader::get_nodes(){
+ return nodes;
+ }
+
+ int AdjMatrixGraphReader::get_num_edges() const {
+ return num_edges;
+ }
+
+ vector AdjMatrixGraphReader::get_weights(){
+ return weights;
+ }
+
+ int AdjMatrixGraphReader::get_capacity() const {
+ return capacity;
+ }
+
+ void AdjMatrixGraphReader::set_capacity(int capacity){
+ }
+}
diff --git a/lib_graphd/src/AdjMatrixGraphWriter.cpp b/lib_graphd/src/AdjMatrixGraphWriter.cpp
new file mode 100644
index 0000000..99fb846
--- /dev/null
+++ b/lib_graphd/src/AdjMatrixGraphWriter.cpp
@@ -0,0 +1,66 @@
+/*
+ This file is part of INDDGO.
+
+ Copyright (C) 2012, Oak Ridge National Laboratory
+
+ This product includes software produced by UT-Battelle, LLC under Contract No.
+ DE-AC05-00OR22725 with the Department of Energy.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the New BSD 3-clause software license (LICENSE).
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ LICENSE for more details.
+
+ For more information please contact the INDDGO developers at:
+ inddgo-info@googlegroups.com
+
+ */
+
+#include "AdjMatrixGraphWriter.h"
+#include "Debug.h"
+#include
+#include
+
+using namespace std;
+
+namespace Graph {
+ AdjMatrixGraphWriter::AdjMatrixGraphWriter(){
+ }
+
+ AdjMatrixGraphWriter::~AdjMatrixGraphWriter(){
+ }
+
+ AdjMatrixGraphWriter::AdjMatrixGraphWriter(string &filename) :
+ GraphWriter(filename){
+ }
+
+ void AdjMatrixGraphWriter::write_graph(Graph *g){
+ FILE *fout = fopen(out_file_name.c_str(), "w");
+ if(!fout){
+ fatal_error("can not open %s for write", out_file_name.c_str());
+ }
+
+ int n = g->get_num_nodes();
+ int i = 0;
+ int j = 0;
+ int val = 0;
+
+ fprintf(fout, "%d \n", n);
+
+ for(i = 0; i < n; i++){
+ for(j = 0; j < n; j++){
+ val = 0;
+ if(g->is_edge(i, j)){
+ val = 1;
+ }
+ fprintf(fout, "%d ", val);
+ }
+ fprintf(fout, "\n");
+ }
+
+ fclose(fout);
+ } // write_graph
+}
diff --git a/lib_graphd/src/DIMACSGraphReader.cpp b/lib_graphd/src/DIMACSGraphReader.cpp
new file mode 100644
index 0000000..4b21e35
--- /dev/null
+++ b/lib_graphd/src/DIMACSGraphReader.cpp
@@ -0,0 +1,236 @@
+/*
+ This file is part of INDDGO.
+
+ Copyright (C) 2012, Oak Ridge National Laboratory
+
+ This product includes software produced by UT-Battelle, LLC under Contract No.
+ DE-AC05-00OR22725 with the Department of Energy.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the New BSD 3-clause software license (LICENSE).
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ LICENSE for more details.
+
+ For more information please contact the INDDGO developers at:
+ inddgo-info@googlegroups.com
+
+ */
+
+#include "DIMACSGraphReader.h"
+#include "Log.h"
+#include
+#include
+#include
+#include "Debug.h"
+
+namespace Graph {
+ DIMACSGraphReader::DIMACSGraphReader(){
+ this->num_edges = 0;
+ }
+
+ void DIMACSGraphReader::read_graph(const char *filename){
+ char line[100], format[100];
+ int i, j, m, n, retval, id;
+ int val;
+ FILE *in;
+
+ m = n = 0;
+ //count = 0;
+ // Use the above to count # of connected nodes, etc. and make sure that it
+ // matches what is in the existing Graph struct.
+
+ if((in = fopen(filename, "r")) == NULL){
+ FERROR("%s: Error opening %s for reading\n", __FUNCTION__, filename);
+ fatal_error("%s: Error opening %s for reading\n", __FUNCTION__,
+ filename);
+ }
+
+ while(!feof(in)){
+ retval = fscanf(in, "%2c", line);
+
+ if(feof(in)){
+ break;
+ }
+
+ if(retval != 1){
+ FERROR("%s: fscanf read %d char's (expected to read 1!)\n",
+ __FUNCTION__, retval);
+ }
+ switch(line[0])
+ {
+ case 'p':
+ // This is the "problem line" - get n and m here
+ // Make sure we don't already know n and m!
+ if((n != 0) || (m != 0) ){
+ FERROR(
+ "%s: DIMACS read error - are there more than one problem lines?\n",
+ __FUNCTION__);
+ }
+ retval = fscanf(in, "%s %d %d", format, &n, &m);
+
+ DEBUG("DIMACS: read n = %d, m = %d\n", n, m);
+
+ // Simple error checking
+ if((n <= 0) || (m <= 0) || (retval != 3) ){
+ FERROR(
+ "%s: DIMACS read error - didn't understand problem line! p %s %d %d\n",
+ __FUNCTION__, format, n, m);
+ exit(-1);
+ }
+
+ if((strncmp(format, "e", 1) != 0) && (strncmp(format, "E", 1) != 0)
+ && (strncmp(format, "edge", 4) != 0)
+ && (strncmp(format, "EDGE", 4) != 0) ){
+ FERROR(
+ "%s: DIMACS read error - problem line - FORMAT must be one of\n"
+ " e, E, edge, or EDGE\n", __FUNCTION__);
+ }
+
+ this->weights.resize(n, 1);
+ this->degree.resize(n, 0);
+ this->nodes.resize(n);
+ this->capacity = n;
+ // Make sure that we match the number of total nodes
+ // if (n != this->capacity)
+ // FERROR("%s: Graph has %d total nodes, file has %d\n",
+ // __FUNCTION__, this->capacity, n);
+ break;
+
+ case 'c':
+ // Comment line - skip and move on
+ break;
+
+ case 'n':
+ // Node line - of the form n id VALUE
+ retval = fscanf(in, "%d %d", &id, &val);
+
+ // Simple error checking - make sure we know n and m already!
+ if((n == 0) || (m == 0) ){
+ FERROR("%s: DIMACS read error - node line found before problem line!\n",
+ __FUNCTION__);
+ }
+ if(retval != 2){
+ FERROR( "%s: DIMACS read error - didn't understand node line\n",
+ __FUNCTION__);
+ }
+ // Check id
+ if((id < 1) || (id > n) ){
+ FERROR("%s: DIMACS read error - node id (%d) must be between 1 and n= %d\n",
+ __FUNCTION__, id, n);
+ }
+ // Store value - first allocate the value array if NULL
+ //if((int)this->weight.size()!=n)
+ // this->weight.resize(n);
+
+ // Store value
+ this->weights[id - 1] = val; // 1->0
+ DEBUG("Storing weight[%d]= %d\n", id - 1, this->weights[id - 1]);
+
+ break;
+
+ case 'e':
+ // Edge line - of the form e start end
+ retval = fscanf(in, "%d %d", &i, &j);
+
+ //DEBUG("Read edge %d-%d\n", i, j);
+
+ // Simple error checking - make sure we know n and m already!
+ if((n == 0) || (m == 0) ){
+ FERROR(
+ "%s: DIMACS read error - edge line found before problem line!\n",
+ __FUNCTION__);
+ }
+ if(retval != 2){
+ FERROR( "%s: DIMACS read error - didn't understand edge line\n",
+ __FUNCTION__);
+ }
+ // Check start and end values
+ if((i < 1) || (i > n) || (j < 1) || (j > n) ){
+ FERROR( "%s: DIMACS read error - edge (u,v) (%d-%d) must have"
+ " both u and v between 1 and n=%d, inclusive\n",
+ __FUNCTION__, i, j, n);
+ }
+
+ // So when we read in an edge (a,b) in the DIMACS file
+ // we need to add G.label_index[b] to nodes[G.label_index[a]]
+ // When going back at the end, we need to use the label field
+ // The edge appears valid - store in adj lists
+
+ this->degree[i - 1]++; // 1->0
+ this->degree[j - 1]++; // 1->0
+
+ this->nodes[i - 1].set_label(i);
+ this->nodes[j - 1].set_label(j);
+ // Add to i's adjlist
+
+ this->nodes[i - 1].add_nbr(j - 1);
+ this->nodes[j - 1].add_nbr(i - 1);
+
+ // Increment edge counter
+ this->num_edges++;
+ //DEBUG("%d:%d\t%d\n", i, j, this->numEdges);
+
+ break;
+ case 'x':
+ // Shows up in TSP files - we don't need it
+ break;
+
+ default:
+ // We encountered some character that we don't understand
+ FERROR("%s: DIMACS read error - didn't understand the character %c to start a line\n",
+ __FUNCTION__, line[0]);
+ break;
+ }; // end switch
+
+ // Advance to next line if there is format at the end of it
+ while(!feof(in) && (getc(in)) != '\n'){
+ ;
+ }
+ }
+ fclose(in);
+ DEBUG("Finish reading DIMACS file\n");
+
+ for(i = 0; i < this->capacity; i++){
+ if(nodes[i].get_label() == -1){
+ nodes[i].set_label(i + 1);
+ }
+ }
+ //#if 1
+ // // Sort the neighbor lists
+ // for (i = 0; i < this->capacity; i++)
+ // if (this->nodes[i].label != GD_UNDEFINED)
+ // this->nodes[i].nbrs.sort();
+ //#endif
+ return;
+ } // read_graph
+
+ std::vector DIMACSGraphReader::get_degree(){
+ return degree;
+ }
+
+ std::vector DIMACSGraphReader::get_nodes(){
+ return nodes;
+ }
+
+ int DIMACSGraphReader::get_num_edges() const {
+ return num_edges;
+ }
+
+ int DIMACSGraphReader::get_capacity() const {
+ return capacity;
+ }
+
+ void DIMACSGraphReader::set_capacity(int capacity){
+ this->capacity = capacity;
+ }
+
+ std::vector DIMACSGraphReader::get_weights(){
+ return weights;
+ }
+
+ DIMACSGraphReader::~DIMACSGraphReader(){
+ }
+}
diff --git a/lib_graphd/src/DIMACSGraphWriter.cpp b/lib_graphd/src/DIMACSGraphWriter.cpp
new file mode 100644
index 0000000..01054a0
--- /dev/null
+++ b/lib_graphd/src/DIMACSGraphWriter.cpp
@@ -0,0 +1,111 @@
+/*
+ This file is part of INDDGO.
+
+ Copyright (C) 2012, Oak Ridge National Laboratory
+
+ This product includes software produced by UT-Battelle, LLC under Contract No.
+ DE-AC05-00OR22725 with the Department of Energy.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the New BSD 3-clause software license (LICENSE).
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ LICENSE for more details.
+
+ For more information please contact the INDDGO developers at:
+ inddgo-info@googlegroups.com
+
+ */
+
+#include "DIMACSGraphWriter.h"
+#include "Debug.h"
+#include
+//#include
+#include
+
+namespace Graph {
+ DIMACSGraphWriter::DIMACSGraphWriter(){
+ }
+
+ DIMACSGraphWriter::DIMACSGraphWriter(string & filename) :
+ GraphWriter(filename){
+ }
+
+ DIMACSGraphWriter::~DIMACSGraphWriter(){
+ }
+
+ /**
+ * Writes the graph to a 1-based DIMACS file. If randomize == true,
+ * we permute the vertex labels (at random) before writing.
+ */
+ void DIMACSGraphWriter::write_graph(Graph *g){
+ int capacity = g->get_capacity();
+ int num_nodes = g->get_num_nodes();
+ int num_edges = g->get_num_edges();
+ vector nodes = g->get_nodes();
+
+ if(perm.size() != capacity){
+ perm.clear();
+ for(int i = 0; i < capacity; i++){
+ perm.push_back(i);
+ }
+ }
+
+ FILE *out;
+ if((out = fopen(out_file_name.c_str(), "w")) == NULL){
+ fatal_error("%s: Couldn't open %s for writing\n", __FUNCTION__,
+ out_file_name.c_str());
+ }
+
+ // Print out a comment line
+ //fprintf(out,"c Graph has %d connected components\n",g->num_connected_components);
+
+ // Will write out non-canonical - note that we may have "holes" in the numbering
+ // Print a warning to stderr and the file in this case
+ if(capacity != num_nodes){
+ fprintf(stderr, "%s: Warning! DIMACS file may have holes.\n",
+ __FUNCTION__);
+ // Print a comment warning in the file
+ fprintf(
+ out,
+ "c Warning: capacity=%d, num_nodes=%d. Resulting graph may have holes\n",
+ capacity, num_nodes);
+ }
+
+ //EDITED TO PRINT p edge instead of p e for compatibility with Koster.
+ fprintf(out, "p edge %d %d\n", num_nodes, num_edges);
+ // Write edges out using the label field from the nodes
+ // Only write out edges u-v with u<=v - so file is at least simple
+ list::iterator ii;
+ int edges_written = 0;
+ list nbrs;
+ for(int i = 0; i < num_nodes; i++){
+ // CSG- could add sort here although that won't work for the randomized labels
+ // g->nodes[perm[i]].nbrs.sort();
+ nbrs = nodes[i].get_nbrs();
+ for(ii = nbrs.begin(); ii != nbrs.end(); ++ii){
+ //if(i<=*ii)
+ // CSG - we want the edges in the file to be u-v with u<=v
+ if(nodes[perm[i]].get_label() <= nodes[perm[*ii]].get_label()){
+ // Changing june 21 for testing - not using labels
+ //if(i<=*ii)
+ edges_written++;
+ fprintf(out, "e %d %d\n", nodes[perm[i]].get_label(),
+ nodes[perm[*ii]].get_label());
+ //,i+1,*ii+1);//
+ }
+ }
+ }
+ if(edges_written != num_edges){
+ fatal_error("%s: Didn't write the correct number of edges! (%d!=%d)\n",
+ __FUNCTION__, edges_written, num_edges);
+ }
+
+ fflush(out);
+ fclose(out);
+
+ return;
+ } // write_graph
+}
diff --git a/lib_graphd/src/Graph.cpp b/lib_graphd/src/Graph.cpp
index 2a6cc61..b9fdf7d 100644
--- a/lib_graphd/src/Graph.cpp
+++ b/lib_graphd/src/Graph.cpp
@@ -28,6 +28,21 @@
#include
#include
+#ifndef _OPENMP
+ #ifdef HAS_METIS
+ void omp_set_num_threads(int num_threads) { return; }
+ int omp_get_num_threads(void) { return 1; }
+ int omp_get_max_threads(void) { return 1; }
+ int omp_get_thread_num(void) { return 0; }
+ int omp_get_num_procs(void) { return 1; }
+ int omp_in_parallel(void) { return 0; }
+ void omp_set_dynamic(int num_threads) { return; }
+ int omp_get_dynamic(void) { return 0; }
+ void omp_set_nested(int nested) { return; }
+ int omp_get_nested(void) { return 0; }
+ #endif
+#endif
+
/* GRAPH_H_ */
namespace Graph {
Graph::Graph(){
@@ -206,51 +221,37 @@ namespace Graph {
return (cnt >> 1);
} // get_num_edges_in_subgraph
- // CSG rewriting this 20130723 - old routine was extremely slow.
- // Have only tested by creating complement graph of DIMACS file and
- // outputting normalized DIMACS of complement graph. Have not tested
- // whether or not all the graph internals are valid, but seems ok.
- // It does everything the old routine did.
void Graph::complement(){
- list *nbr_list_ptr;
- int num_edges = 0 ;
- int *el_vec;
- el_vec=new int[this->capacity];
- memset(el_vec,-1,this->capacity*sizeof(int));
-
- for(int i = 0; i < this->capacity; i++)
- {
- // The only parts of el_vec we care about for node index i is position
- // i and the position of i's nbrs
- // So stick a value of i in these positions and just check for that -
- // we will constantly overwrite this vec (adj_vec style), but
- // that won't matter and we save time by not having to memset el_vec over and
- // over, etc.
-
- // eliminate self-loop
- el_vec[i]=i;
- // Get ptr to node i's nbr list
- nbr_list_ptr = this->nodes[i].get_nbrs_ptr();
- for(list::iterator ii=nbr_list_ptr->begin();ii!=nbr_list_ptr->end();++ii)
- el_vec[*ii]=i;
-
- int num_nbrs=0;
- this->nodes[i].nbrs.clear();
- for(int j=0; j< this->capacity; j++)
- if(el_vec[j]!=i)
- {
- // want to avoid calling size()!
- num_nbrs++;
- this->nodes[i].nbrs.push_back(j);
- }
-
- this->degree[i] = num_nbrs;
- num_edges += this->degree[i];
- }
-
- this->set_num_edges(num_edges / 2);
- delete [] el_vec;
- }
+ Node *n;
+
+ list elements;
+ list newnbrs;
+ list nbrs;
+ list::iterator it;
+ int edge = 0;
+
+ for(int i = 0; i < this->capacity; i++){
+ elements.push_back(i);
+ }
+
+ for(int i = 0; i < this->capacity; i++){
+ n = this->get_node(i);
+ nbrs = n->get_nbrs();
+ newnbrs = elements;
+ nbrs.sort();
+
+ newnbrs.remove(i);
+ for(it = nbrs.begin(); it != nbrs.end(); ++it){
+ newnbrs.remove(*it);
+ }
+
+ this->degree[i] = newnbrs.size();
+ edge += this->degree[i];
+ n->set_nbr(newnbrs);
+ }
+
+ this->set_num_edges(edge / 2);
+ } // complement
bool Graph::is_canonical() const {
return canonical;
diff --git a/lib_graphd/src/GraphCreator.cpp b/lib_graphd/src/GraphCreator.cpp
index d6d29f9..18eabf6 100644
--- a/lib_graphd/src/GraphCreator.cpp
+++ b/lib_graphd/src/GraphCreator.cpp
@@ -29,6 +29,106 @@ namespace Graph {
GraphCreator::GraphCreator(){
}
+ /**
+ * Initialization of an R-MAT graph with 2^l vertices and <= m edges.
+ * Four probabilities in *probs used for quadrants, must sum to 1.
+ * lc rng initialized with seed. Setting self_loop true throws another
+ * edge if a self loop occurs.
+ */
+ Graph *GraphCreator::initialize_rmat(int l, int m, double *probs, int seed, bool self_loop) {
+ try {
+ //check neighborhood to account for float errors
+ if(probs[0]+probs[1]+probs[2]+probs[3] > 1.001 || probs[0]+probs[1]+probs[2]+probs[3] < 0.999) {
+ fatal_error("initialize_rmat: Probabilities did not sum to 1: %f, %f, %f, %f", probs[0], probs[1], probs[2], probs[3]);
+ }
+ } catch(...) {
+ fatal_error("initialize_rmat: Error occured when checking probabilities");
+ }
+
+ //set up quadrants
+ const double q1 = probs[0];
+ const double q2 = probs[0] + probs[1];
+ const double q3 = probs[0] + probs[1] + probs[2];
+ set< pair > edges;
+
+ //set up rng
+ init_lcgrand(0,seed);
+
+ //throw m edges
+ for(int i = 0; i < m; i++) {
+ unsigned long x = 0;
+ unsigned long y = 0;
+ for(int j = l-1; j >= 0; j--) {
+ double r = lcgrand(0);
+ if(r < q1) {
+ } else if(r < q2) {
+ x += pow(2,j);
+ } else if(r < q3) {
+ y += pow(2,j);
+ } else {
+ x += pow(2,j);
+ y += pow(2,j);
+ }
+ }
+
+ //keep edges in order so we don't have a (x,y) and (y,x) duplicate
+ if(x == y) {
+ if(self_loop) {
+ i--;
+ }
+ } else if(y > x) {
+ edges.insert(make_pair(x,y));
+ } else {
+ edges.insert(make_pair(y,x));
+ }
+ }
+
+ Graph *g = new Graph(pow(2,l));
+ set< pair >::const_iterator it;
+ for(it = edges.begin(); it != edges.end(); it++) {
+ g->add_edge(it->first,it->second);
+ }
+
+ return g;
+ } //initialize_rmat
+
+
+ /**
+ * Initialization of a random intersection graph with n vertices, probs->size() attributes,
+ * with probabilities on the attributes. lc rng initialized with seed.
+ */
+ Graph *GraphCreator::initialize_rig(int n, int seed, list *probs) {
+ set< pair > edges;
+ init_lcgrand(0, seed);
+
+ //for all the attributes, construct a clique in G
+ list::const_iterator it;
+ for(it = probs->begin(); it != probs->end(); it++) {
+ //compute which actors have a given attribute
+ vector connect;
+ for(unsigned long i = 0; i < n; i++) {
+ if(lcgrand(0) < *it) {
+ connect.push_back(i);
+ }
+ }
+ //attach these actors to the graph
+ for(int i = 0; i < connect.size(); i++) {
+ for(int j = i + 1; j < connect.size(); j++) {
+ edges.insert(make_pair(connect[i],connect[j]));
+ }
+ }
+ }
+
+ Graph *g = new Graph(n);
+ set< pair >::const_iterator edge_it;
+ for(edge_it = edges.begin(); edge_it != edges.end(); edge_it++) {
+ g->add_edge(edge_it->first,edge_it->second);
+ }
+
+ return g;
+ } //initialize_rig
+
+
/**
* Initialization of a k-tree with n vertices. RNG seeded with seed.
* mg starts with a clique on vertices 0 through k and iteratively
diff --git a/lib_graphd/src/GraphProperties.cpp b/lib_graphd/src/GraphProperties.cpp
index c898ab5..a14331c 100644
--- a/lib_graphd/src/GraphProperties.cpp
+++ b/lib_graphd/src/GraphProperties.cpp
@@ -23,9 +23,7 @@
//No longer used 7/22/13
//#include
#include
-#if !WIN32 && !WIN64
#include
-#endif
#include
@@ -374,8 +372,10 @@ namespace Graph {
* \param[out] t output vector of per-vertex triangle counts
*/
void GraphProperties::all_triangles_compact_forward(Graph *g, vector &t){
- int i;
+ int i, j;
int u, v;
+ int retcode;
+ Node *vn;
std::list::const_reverse_iterator rit;
@@ -406,6 +406,8 @@ namespace Graph {
*/
Node *nv, *nu;
+ int vp, up;
+ int iu, iv;
int fakev;
int uprime, vprime;
const int n = g->get_num_nodes();
@@ -491,8 +493,7 @@ namespace Graph {
} //for vtxs
} //for fakev
#pragma omp for
- int tsize=(int) t.size();
- for(i = 0; i < tsize; i++){
+ for(i = 0; i < t.size(); i++){
for(int j = 0; j < omp_get_num_threads(); j++){
t[i] += local_t[j][i];
}
@@ -506,7 +507,7 @@ namespace Graph {
* \param[out] t vector of long ints, length |V|, returns 3x number of triangles for each vertex
*/
void GraphProperties::all_triangles_edge_listing(Graph *g, vector &t){
- int i, u, v;
+ int i, j, u, v;
vector::iterator it;
list::const_iterator cit;
list::iterator lt;
@@ -756,9 +757,8 @@ namespace Graph {
}
//compute diameter of each vertex
- int esize= (int)ecc.size();
- for(int i = 0; i < esize ; i++){
- if(ecc[i] > (int)freq_ecc.size() ){
+ for(int i = 0; i < ecc.size(); i++){
+ if(ecc[i] > freq_ecc.size() ){
freq_ecc.resize(ecc[i] + 1); //because vector numbering starts at 0
}
freq_ecc[ecc[i]]++; //add to tally for this diameter size
@@ -766,7 +766,7 @@ namespace Graph {
//printf("Graph diameter is %d\n", freq_ecc.size()-1);
#pragma omp parallel for default(none) shared(freq_ecc)
- for(int i = 0; i <= (int)freq_ecc.size() - 1; i++){
+ for(int i = 0; i <= freq_ecc.size() - 1; i++){
freq_ecc[i] = freq_ecc[i] / n;
//printf("i=%d and n=%d with freq eccentricity %f\n",i,n,freq_ecc[i]);
}
@@ -864,7 +864,7 @@ namespace Graph {
gd = numer / float(tot_con_pairs);
}
- ediam = (float)((tot_con_pairs * 0.9 - n0) / float(numer - n0) + d - 1);
+ ediam = (tot_con_pairs * 0.9 - n0) / float(numer - n0) + d - 1;
} // effective_diameter
/**
@@ -876,7 +876,7 @@ namespace Graph {
int V = g->num_nodes;
int E = g->num_edges;
- ed = (float)((2.0 * E) / (V * (V - 1.0)));
+ ed = (2.0 * E) / (V * (V - 1.0));
}
/**
@@ -888,7 +888,7 @@ namespace Graph {
int V = g->num_nodes;
int E = g->num_edges;
- ad = (float)((2.0 * E) / V);
+ ad = (2.0 * E) / V;
}
/**
@@ -920,6 +920,7 @@ namespace Graph {
const vector °rees = g->get_degree_ref();
int i;
double di, dc;
+ int nbr;
std::list::const_iterator cit;
Node *node;
diff --git a/lib_graphd/src/GraphReader.cpp b/lib_graphd/src/GraphReader.cpp
index dddaac6..1f25781 100644
--- a/lib_graphd/src/GraphReader.cpp
+++ b/lib_graphd/src/GraphReader.cpp
@@ -23,10 +23,7 @@
#include "Log.h"
#include "Debug.h"
#include "Util.h"
-// CSG - why is this included again here?
-#if !WIN32 && !WIN64
#include
-#endif
#include
#include
#include
@@ -36,14 +33,6 @@
#include
#include
-// CSG - to handle strncasecmp
-#if defined(WIN32) || defined(_WIN64)
- #define snprintf _snprintf
- #define vsnprintf _vsnprintf
- #define strcasecmp _stricmp
- #define strncasecmp _strnicmp
-#endif
-
namespace Graph {
GraphReader::GraphReader(){
}
@@ -116,8 +105,8 @@ namespace Graph {
* \return code 0 on success, nonzero on failure
*/
int GraphReader::read_adjlist(Graph *g, const string filename){
- //int i, j, m, n, retval;
- //char *retp;
+ int i, j, m, n, retval;
+ char *retp;
int new_vid;
int new_nbr;
@@ -147,8 +136,6 @@ namespace Graph {
}
}
}
- // CSG - adding return value of 0
- return 0;
} // read_adjlist
/**
diff --git a/lib_graphd/src/GraphUtil.cpp b/lib_graphd/src/GraphUtil.cpp
index 14c4dcb..1168e63 100644
--- a/lib_graphd/src/GraphUtil.cpp
+++ b/lib_graphd/src/GraphUtil.cpp
@@ -778,17 +778,14 @@ namespace Graph {
vector deg_lookup(n);
int max_deg = 0;
- int deg_size= (int)deg_lookup.size();
- for(int i = 0; i < deg_size; i++) {
+ for(int i = 0; i < deg_lookup.size(); i++) {
deg_lookup[i] = g->degree[i];
if(deg_lookup[i] > max_deg)
max_deg = deg_lookup[i];
}
vector > D;
D.resize(max_deg+1);
- //int depth[n];
- int *depth;
- depth = new int[n];
+ int depth[n];
//can also create an L output list for coloring number optimal ordering
for(int i = 0; i < n; i++) {
@@ -825,8 +822,6 @@ namespace Graph {
}
}
}
- // CSG
- delete [] depth;
return k;
} // find_degen
diff --git a/lib_graphd/src/GraphVizGraphWriter.cpp b/lib_graphd/src/GraphVizGraphWriter.cpp
new file mode 100644
index 0000000..20b7195
--- /dev/null
+++ b/lib_graphd/src/GraphVizGraphWriter.cpp
@@ -0,0 +1,75 @@
+/*
+ This file is part of INDDGO.
+
+ Copyright (C) 2012, Oak Ridge National Laboratory
+
+ This product includes software produced by UT-Battelle, LLC under Contract No.
+ DE-AC05-00OR22725 with the Department of Energy.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the New BSD 3-clause software license (LICENSE).
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ LICENSE for more details.
+
+ For more information please contact the INDDGO developers at:
+ inddgo-info@googlegroups.com
+
+ */
+
+#include "GraphVizGraphWriter.h"
+#include "Debug.h"
+#include
+
+namespace Graph {
+ GraphVizGraphWriter::GraphVizGraphWriter(){
+ }
+
+ GraphVizGraphWriter::GraphVizGraphWriter(string & outfile) :
+ GraphWriter(outfile){
+ }
+
+ GraphVizGraphWriter::~GraphVizGraphWriter(){
+ }
+
+ /**
+ * Writes the graph to the provide graph_viz file.
+ */
+ void GraphVizGraphWriter::write_graph(Graph *g){
+ int i, j;
+ FILE *out;
+ string graphviz_file = out_file_name;
+ if((out = fopen(graphviz_file.c_str(), "w")) == NULL
+ ){
+ fatal_error(
+ "%s: Error opening file %s for writing graphviz output\n",
+ __FUNCTION__, graphviz_file.c_str());
+ }
+
+ fprintf(out, "Graph G{\n");
+ fprintf(out, "overlap=false;\n");
+ list::iterator it;
+ vector nodes = g->get_nodes();
+ list nbrs;
+
+ for(i = 0; i < g->get_num_nodes(); i++){
+ nbrs = nodes[i].get_nbrs();
+ it = nbrs.begin();
+ while(it != nbrs.end()){
+ j = *it;
+ if(i < j){
+ // Make this 1-based in true DIMACS spirit
+ fprintf(out, "%d -- %d;\n", i + 1, j + 1);
+ }
+ ++it;
+ }
+ }
+ fprintf(out, "}\n");
+ fflush(out);
+ fclose(out);
+
+ return;
+ } // write_graph
+}
diff --git a/lib_graphd/src/GraphWriter.cpp b/lib_graphd/src/GraphWriter.cpp
index 104c10d..6d7dcdb 100644
--- a/lib_graphd/src/GraphWriter.cpp
+++ b/lib_graphd/src/GraphWriter.cpp
@@ -204,6 +204,8 @@ namespace Graph {
int capacity = g->get_capacity();
int num_nodes = g->get_num_nodes();
int num_edges = g->get_num_edges();
+ //vector nodes = g->get_nodes();
+ Node *n;
for(int i = 0; i < capacity; i++){
perm.push_back(i);
diff --git a/lib_graphd/src/MetisGraphReader.cpp b/lib_graphd/src/MetisGraphReader.cpp
new file mode 100644
index 0000000..0a46ea1
--- /dev/null
+++ b/lib_graphd/src/MetisGraphReader.cpp
@@ -0,0 +1,137 @@
+/*
+ This file is part of INDDGO.
+
+ Copyright (C) 2012, Oak Ridge National Laboratory
+
+ This product includes software produced by UT-Battelle, LLC under Contract No.
+ DE-AC05-00OR22725 with the Department of Energy.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the New BSD 3-clause software license (LICENSE).
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ LICENSE for more details.
+
+ For more information please contact the INDDGO developers at:
+ inddgo-info@googlegroups.com
+
+ */
+
+#include "MetisGraphReader.h"
+#include "Debug.h"
+#include "Log.h"
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+namespace Graph {
+ MetisGraphReader::MetisGraphReader(){
+ }
+
+ MetisGraphReader::MetisGraphReader(string f) :
+ filename(f){
+ }
+
+ MetisGraphReader::~MetisGraphReader(){
+ }
+
+ void MetisGraphReader::split(const string& s, char c, vector& v){
+ string::size_type i = 0;
+ string::size_type j = s.find(c);
+ stringstream ss;
+ int k;
+ while(j != string::npos){
+ //v.push_back(s.substr(i, j - i));
+ k = 0;
+ ss.clear();
+ ss << s.substr(i, j - i);
+ ss >> k;
+ v.push_back(k);
+ i = ++j;
+ j = s.find(c, j);
+ if(j == string::npos){
+ k = 0;
+ //v.push_back(s.substr(i, s.length( )));
+ ss.clear();
+ ss << s.substr(i, s.length());
+ ss >> k;
+ if(k > 0){
+ v.push_back(k);
+ }
+ }
+ }
+ } // split
+
+ void MetisGraphReader::read_graph(const char *filename){
+ // here we assume metis graphs are based on 1.
+ string s;
+ ifstream in(filename);
+ vector elem;
+ int n, e = 0;
+ int count = 0;
+
+ if(in.is_open()){
+ elem.clear();
+ getline(in, s);
+ split(s, ' ', elem);
+ n = elem[0];
+ e = elem[1];
+
+ if((n <= 0) || (e <= 0) ){
+ fatal_error("Metis read error - didn't understand problem line!");
+ }
+
+ this->weights.resize(n, 1);
+ this->degree.resize(n, 0);
+ this->nodes.resize(n);
+ this->capacity = n;
+
+ while(in.good()){
+ getline(in, s);
+ elem.clear();
+ split(s, ' ', elem);
+ int is = (int) elem.size();
+ for(int i = 0; i < is; i++){
+ this->nodes[count].add_nbr(elem[i] - 1);
+ this->degree[count]++;
+ }
+ count++;
+ }
+
+ in.close();
+ }
+ } // read_graph
+
+ void MetisGraphReader::read_graph(){
+ this->read_graph(filename.c_str());
+ }
+
+ vector MetisGraphReader::get_degree(){
+ return degree;
+ }
+
+ vector MetisGraphReader::get_nodes(){
+ return nodes;
+ }
+
+ int MetisGraphReader::get_num_edges() const {
+ return num_edges;
+ }
+
+ vector MetisGraphReader::get_weights(){
+ return weights;
+ }
+
+ int MetisGraphReader::get_capacity() const {
+ return capacity;
+ }
+
+ void MetisGraphReader::set_capacity(int capacity){
+ this->capacity = capacity;
+ }
+}
diff --git a/lib_graphd/src/MetisGraphWriter.cpp b/lib_graphd/src/MetisGraphWriter.cpp
new file mode 100644
index 0000000..c2fae0b
--- /dev/null
+++ b/lib_graphd/src/MetisGraphWriter.cpp
@@ -0,0 +1,77 @@
+/*
+ This file is part of INDDGO.
+
+ Copyright (C) 2012, Oak Ridge National Laboratory
+
+ This product includes software produced by UT-Battelle, LLC under Contract No.
+ DE-AC05-00OR22725 with the Department of Energy.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the New BSD 3-clause software license (LICENSE).
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ LICENSE for more details.
+
+ For more information please contact the INDDGO developers at:
+ inddgo-info@googlegroups.com
+
+ */
+
+#include "MetisGraphWriter.h"
+#include "Debug.h"
+#include
+
+namespace Graph {
+ MetisGraphWriter::MetisGraphWriter(){
+ }
+
+ MetisGraphWriter::MetisGraphWriter(string & filename) :
+ GraphWriter(filename){
+ }
+
+ MetisGraphWriter::~MetisGraphWriter(){
+ }
+
+ /**
+ * Writes the graph to a 1-based Metis file.
+ */
+ void MetisGraphWriter::write_graph(Graph *g){
+ int capacity = g->get_capacity();
+ int num_nodes = g->get_num_nodes();
+ int num_edges = g->get_num_edges();
+ vector nodes = g->get_nodes();
+
+ FILE *out;
+ if((out = fopen(out_file_name.c_str(), "w")) == NULL){
+ fatal_error("%s: Couldn't open %s for writing\n", __FUNCTION__,
+ out_file_name.c_str());
+ }
+
+ if(capacity != num_nodes){
+ fprintf(stderr, "%s: Warning! Metis file may have holes.\n",
+ __FUNCTION__);
+ // Print a comment warning in the file
+ fprintf(
+ out,
+ "c Warning: capacity=%d, num_nodes=%d. Resulting graph may have holes\n",
+ capacity, num_nodes);
+ }
+
+ fprintf(out, "%d %d\n", num_nodes, num_edges);
+ list::iterator ii;
+ list *nbrs;
+ for(int i = 0; i < num_nodes; i++){
+ nbrs = nodes[i].get_nbrs_ptr();
+ for(ii = nbrs->begin(); ii != nbrs->end(); ++ii){
+ fprintf(out, "%d ", (*ii) + 1);
+ }
+ fprintf(out, "\n");
+ }
+
+ fflush(out);
+ fclose(out);
+ return;
+ } // write_graph
+}
diff --git a/lib_graphd/src/Node.cpp b/lib_graphd/src/Node.cpp
index aa25409..39f4048 100644
--- a/lib_graphd/src/Node.cpp
+++ b/lib_graphd/src/Node.cpp
@@ -100,6 +100,7 @@ namespace Graph {
std::list::const_reverse_iterator Node::get_largest_neighbor_below(int n){
//FIXME: probably should be able to handle unsorted case, but how to do without sacrificing efficiency?
// also maybe do a binary instead of linear search
+ int v;
std::list::reverse_iterator it;
for(it = this->nbrs.rbegin(); it != this->nbrs.rend(); it++){
diff --git a/lib_graphd/src/RndNumGen.cpp b/lib_graphd/src/RndNumGen.cpp
index deb0b64..8ec6e2c 100644
--- a/lib_graphd/src/RndNumGen.cpp
+++ b/lib_graphd/src/RndNumGen.cpp
@@ -27,6 +27,7 @@
// A collection of random seeds from Mathematica for the LCG -
+static int zrng_count = 300;
static long long zrng[] =
{
1585898122, 977263903, 1405617513, 992686252, 18121536, 2063068841, 754752318,
@@ -86,11 +87,22 @@ static int initialized = 0;
#endif
namespace Graph {
+ void init_lcgrand(int stream, int seed) {
+ if(stream < 0 || stream > zrng_count) {
+ fatal_error("lcgrand: Stream was %d, must be in range 0-%d", stream, zrng_count-1);
+ }
+ zrng[stream] = seed;
+ }
+
double lcgrand(int stream){
///
/// A run of the mill LCG. Returns a uniformly distributed double in (0,1).
///
+ if(stream < 0 || stream > zrng_count) {
+ fatal_error("lcgrand: Stream was %d, must be in range 0-%d", stream, zrng_count-1);
+ }
+
long long zi;
#if TD_ADD_ENTROPY
// Add a time component to the RNG to get different
diff --git a/lib_graphd/src/Util.cpp b/lib_graphd/src/Util.cpp
index 9b41176..2db0a22 100644
--- a/lib_graphd/src/Util.cpp
+++ b/lib_graphd/src/Util.cpp
@@ -851,8 +851,7 @@ void write_degree_distribution(string filename, const vector &dist){
}
else {
int i;
- int d_size=(int)dist.size();
- for(i = 0; i < d_size; i++){
+ for(i = 0; i < dist.size(); i++){
outfile << dist[i] << "\n";
}
}
diff --git a/util/src/complement.cpp b/util/src/complement.cpp
deleted file mode 100755
index d63b6b5..0000000
--- a/util/src/complement.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
-This file is part of INDDGO.
-
-Copyright (C) 2012, Oak Ridge National Laboratory
-
-This product includes software produced by UT-Battelle, LLC under Contract No.
-DE-AC05-00OR22725 with the Department of Energy.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the New BSD 3-clause software license (LICENSE).
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-LICENSE for more details.
-
-For more information please contact the INDDGO developers at:
-inddgo-info@googlegroups.com
-
-*/
-
-#include "GraphDecomposition.h"
-#include "TreeDecomposition.h"
-#include "Log.h"
-#include "GraphException.h"
-#include
-#include
-
-#include "VertexWeightedGraph.h"
-
-void usage(char *str)
-{
- fprintf(stderr,"%s \n\tWrites the complement graph of the provided\n"
- "\tDIMACS file to .comp.norm\n"
- "\tin normalized DIMACS form\n", str);
- exit(-1);
-};
-
-int main(int argc, char **argv)
-{
- if(argc!=2 || strcmp(argv[1],"-h")==0 || strcmp(argv[1],"--help")==0)
- usage(argv[0]);
-
- Graph::VertexWeightedGraph *G;
-
- Graph::GraphCreatorFile creator;
- creator.set_file_name(argv[1]);
- creator.set_graph_type("DIMACS");
- G = creator.create_weighted_mutable_graph();
- G->complement();
- Graph::GraphWriter writer;
-
- char comp_DIMACS_file[200];
- char normalized_comp_DIMACS_file[200];
- sprintf(comp_DIMACS_file,"%s.comp",argv[1]);
- writer.write_graph(G,comp_DIMACS_file,"DIMACS",true,false);
- // Now normalize it
- sprintf(normalized_comp_DIMACS_file,"%s.norm",comp_DIMACS_file);
- normalize_DIMACS_file(comp_DIMACS_file,normalized_comp_DIMACS_file);
- fprintf(stderr,"Complement graph of %s written to %s in normalized DIMACS form\n",
- argv[1],normalized_comp_DIMACS_file);
-
- delete G;
- return 1;
-}
-