diff --git a/Headers.h b/Headers.h index 52aece8..9d6e499 100644 --- a/Headers.h +++ b/Headers.h @@ -7,6 +7,8 @@ #include #include #include +#include +#include diff --git a/LatticeStuff.cpp b/LatticeStuff.cpp index e899b5d..49b751f 100644 --- a/LatticeStuff.cpp +++ b/LatticeStuff.cpp @@ -1,7 +1,7 @@ #include "Headers.h" #include "Parameters.h" // >> contains all the req parameters -void create_Bmat_bimodal(std::vector & Bmat) +void create_Bmat_bimodal(std::vector & Bmat,float del) { long i = 0, var = 0, count1 = 0, count2 = 0; std::uniform_int_distribution distr(0, 1000); @@ -14,12 +14,12 @@ void create_Bmat_bimodal(std::vector & Bmat) var = distr(generator); if (var < 500) { - Bmat[i] = w; + Bmat[i] = del; count1++; } else { - Bmat[i] = -w; + Bmat[i] = -del; count2++; } //std::cout << Bmat[i] << d; @@ -29,7 +29,7 @@ void create_Bmat_bimodal(std::vector & Bmat) } // http://www.cplusplus.com/reference/random/normal_distribution/ -void create_Bmat_gaussian(std::vector & Bmat,int del) +void create_Bmat_gaussian(std::vector & Bmat,float del) { double var = 0; long i = 0, count1 = 0, count2 = 0; @@ -77,7 +77,7 @@ void create_Exmat(std::vector < std::vector >& Exmat, std::vector & } -void create_CapacityMat(std::vector < std::vector >& CapacityMat, std::vector < std::vector >& Exmat) +void create_CapacityMat(std::vector < std::vector >& CapacityMat, std::vector < std::vector >& Exmat) { for (int i = 1; i <= N; i++) { @@ -86,7 +86,7 @@ void create_CapacityMat(std::vector < std::vector >& CapacityMat, std::vec { if (i < j) { - CapacityMat[i][j] = 4 * J * Exmat[i - 1][j - 1] * 10; + CapacityMat[i][j] = 4 * J * Exmat[i - 1][j - 1] ; } else @@ -97,7 +97,7 @@ void create_CapacityMat(std::vector < std::vector >& CapacityMat, std::vec } -void create_Wmat(std::vector < int >& Wmat,std::vector < std::vector >& CapacityMat, std::vector < int >& Bmat, int del ) +void create_Wmat(std::vector < float >& Wmat,std::vector < std::vector >& CapacityMat, std::vector < float >& Bmat, float del ) { int i = 0, j = 0, cap = 0; for (i = 1; i <= N; i++) @@ -109,12 +109,12 @@ void create_Wmat(std::vector < int >& Wmat,std::vector < std::vector >& Ca } Wmat[i - 1] = -2 * Bmat[i - 1] * del - cap / 2; cap = 0; - //cout <& Wmat, std::vector < std::vector >& CapacityMat) +void create_Augumented_CapacityMat(std::vector < float >& Wmat, std::vector < std::vector >& CapacityMat) { int i = 0; for (i = 1; i <= N; i++) @@ -134,7 +134,7 @@ void create_Augumented_CapacityMat(std::vector < int >& Wmat, std::vector < std: } } -void create_Residual_graph(std::vector < std::vector >& CapacityMat, std::vector < std::vector >& flow) +void create_Residual_graph(std::vector < std::vector >& CapacityMat, std::vector < std::vector >& flow) { int i = 0, j = 0; for (i = 0; i < V; i++) @@ -152,7 +152,7 @@ void printMatrix(std::vector > & M, int len) { int i, j; for (i = 0; i < len; i++) { for (j = 0; j < len; j++) - std::cout << "\t" << M[i][j]; + std::cout << "\t" << M[i][j]; std::cout << "\n"; } } @@ -164,3 +164,53 @@ void printMatrix(std::vector & M, int len) { }std::cout << "\n"; } + + +void savedata(std::vector< int > & Mat,int l,float del,std::string s) +{ + std::ofstream fobj(s+"-" + std::to_string(l) + "-" + std::to_string(del) + ".csv"); + //fobj << "iteration : " << l << "\ndelta : " << del << std::endl; + int j; + Mat.erase(Mat.begin() + 1); + for (int i = 0; i < Mat.size(); i++) + { + std::cout << Mat[i]; + } + + for (int i = 0; i < N; i++) + { + if (i%VER == 0) fobj << std::endl; + fobj << Mat[i]<<","; + + } + + + + fobj.clear(); +} + + + + + +void savedata(std::vector< float > & Mat, int l, float del, std::string s) +{ + std::ofstream fobj(s + "-" + std::to_string(l) + "-" + std::to_string(del) + ".csv"); + //fobj << "iteration : " << l << "\ndelta : " << del << std::endl; + + + + for (int i = 0; i < N; i++) + { + + if (i%VER == 0) fobj << std::endl; + fobj << Mat[i] << ","; + + } + + + fobj.clear(); +} + + + diff --git a/LatticeStuff.h b/LatticeStuff.h index df3957d..ccda3dc 100644 --- a/LatticeStuff.h +++ b/LatticeStuff.h @@ -2,21 +2,24 @@ #include "Headers.h" -void create_Bmat_bimodal(std::vector & Bmat); +void create_Bmat_bimodal(std::vector & Bmat,float del); -void create_Bmat_gaussian(std::vector & Bmat,int del); +void create_Bmat_gaussian(std::vector & Bmat, float del); void create_Exmat(std::vector < std::vector >& Exmat, std::vector & latt); -void create_CapacityMat(std::vector < std::vector >& CapacityMat, std::vector < std::vector >& Exmat); +void create_CapacityMat(std::vector < std::vector >& CapacityMat, std::vector < std::vector >& Exmat); -void create_Wmat(std::vector < int >& Wmat, std::vector < std::vector >& CapacityMat, std::vector & BMat, int del); +void create_Wmat(std::vector < float >& Wmat, std::vector < std::vector >& CapacityMat, std::vector & BMat, float del); -void create_Augumented_CapacityMat(std::vector < int >& Wmat, std::vector < std::vector >& CapacityMat); +void create_Augumented_CapacityMat(std::vector < float >& Wmat, std::vector < std::vector >& CapacityMat); -void create_Residual_graph(std::vector < std::vector >& CapacityMat, std::vector < std::vector >& flow); +void create_Residual_graph(std::vector < std::vector >& CapacityMat, std::vector < std::vector >& flow); void printMatrix(std::vector > const & M, int len); void printMatrix(std::vector const & M, int len); +void savedata(std::vector< int > & Mat, int l, float del, std::string s); + +void savedata(std::vector< float > & Mat, int l, float del, std::string s); \ No newline at end of file diff --git a/Parameters.h b/Parameters.h index ae062ee..7b2d1dc 100644 --- a/Parameters.h +++ b/Parameters.h @@ -1,8 +1,8 @@ #pragma once //* DEFINE ALL THE PARAMETERS HERE */ -#define iter 10 -#define VER 10 // width of lattice matrix. for ex 6*6 lattice +#define iter 1 +#define VER 32 // width of lattice matrix. for ex 6*6 lattice #define DIM 2 // dimension of lattice // here 2; square lattice #define latt_pc 1 // percentage of lattice points where atom exist #define upspin_pc 0.5 // percentage of upspin in lattice @@ -14,13 +14,11 @@ #define HIGH INFINITE //delta is multipling factor with Bmat -#define del_beg 0 -#define del_end 40 -#define del_inc 2 - - - +#define del_beg .7 +#define del_end 1.2 +#define del_inc .1 + // text substitute #define tab "\t" #define d " : " diff --git a/PushRelabel.cpp b/PushRelabel.cpp index 5f14147..77f184b 100644 --- a/PushRelabel.cpp +++ b/PushRelabel.cpp @@ -2,28 +2,28 @@ #include "Parameters.h" // >> contains all the req parameters -void push(std::vector >const& C1, std::vector >& F1, std::vector & excess1, int u, int v) { +void push(std::vector >const& C1, std::vector >& F1, std::vector & excess1, int u, int v) { //std::cout << "\nin push\n"; - int send = MIN(excess1[u], C1[u][v] - F1[u][v]); + float send = std::min(excess1[u], C1[u][v] - F1[u][v]); F1[u][v] += send; F1[v][u] -= send; excess1[u] -= send; excess1[v] += send; } -void relabel(std::vector >const & C, std::vector >& F, std::vector & height, int u) { +void relabel(std::vector >const & C, std::vector >& F, std::vector & height, int u) { int v; int min_height = INFINITE; for (v = 0; v < V; v++) { if (C[u][v] - F[u][v] > 0) { - min_height = MIN(min_height, height[v]); + min_height = std::min(min_height, height[v]); height[u] = min_height + 1; } } } //void discharge(const int * const * C, int ** F, int *excess, int *height, int *seen, int u) { -void discharge(std::vector >const & C, std::vector >& F, std::vector & excess, std::vector & height, std::vector & seen, int u) { +void discharge(std::vector >const & C, std::vector >& F, std::vector & excess, std::vector & height, std::vector & seen, int u) { //std::cout << "\nflag 2\n"; while (excess[u] > 0) { @@ -53,9 +53,10 @@ void moveToFront(int i, std::vector & A) { } //int pushRelabel(const int * const * C, int ** F, int source, int sink) { -void pushRelabel(std::vector >const& C, std::vector >& F, int source, int sink) { +void pushRelabel(std::vector >const& C, std::vector >& F, int source, int sink) { //int *excess, *height, *list, *seen, i, p; - std::vector excess(V, 0), height(V, 0), list(V - 2, 0), seen(V, 0); + std::vector height(V, 0), list(V - 2, 0), seen(V, 0); + std::vector excess(V, 0); int i, p; //std::cout << "add in fn " << &C[100][70]; /*excess = new int[V]; @@ -97,7 +98,7 @@ void pushRelabel(std::vector >const& C, std::vector >const& C1, std::vector >& F1, std::vector & excess1, int u, int v); +void push(std::vector >const& C1, std::vector >& F1, std::vector & excess1, int u, int v); -void relabel(std::vector >const & C, std::vector >& F, std::vector & height, int u); +void relabel(std::vector >const & C, std::vector >& F, std::vector & height, int u); -void discharge(std::vector >const & C, std::vector >& F, std::vector & excess, std::vector & height, std::vector & seen, int u); +void discharge(std::vector >const & C, std::vector >& F, std::vector & excess, std::vector & height, std::vector & seen, int u); void moveToFront(int i, std::vector & A); -void pushRelabel(std::vector >const& C, std::vector >& F, int source, int sink); +void pushRelabel(std::vector >const& C, std::vector >& F, int source, int sink); diff --git a/RFIM_2D_main.cpp b/RFIM_2D_main.cpp index d62db9d..e2532cf 100644 --- a/RFIM_2D_main.cpp +++ b/RFIM_2D_main.cpp @@ -20,7 +20,7 @@ int main(void) { // storing data into csv file ofstream file("log_rfim_2D.csv"); file << "\niter,del,m=(mag/N)^2" << endl; - time_t time_begin, time_end, time_1, time_2; + time_t time_begin=0, time_end=0, time_1=0, time_2=0; long t1, t2, tdiff[iter] = { 0 }, l = 0, sum = 0, i, j, cap = 0, clusters = 0; @@ -30,15 +30,14 @@ int main(void) { /* ==================== INITIALISING 2D VECTORS ================*/ - vector < vector > flow(V, vector(V, 0)) - , CapacityMat(V, vector(V, 0)) - , Exmat(N, vector(N, 0)) + vector < vector > Exmat(N, vector(N, 0)) , sqlat0(VER + 1, vector(VER + 1, 0)) , sqlat1(VER + 1, vector(VER + 1, 0)); - + vector < vector > flow(V, vector(V, 0)) + , CapacityMat(V, vector(V, 0)); /* ==================== INITIALISING 1D VECTORS ================*/ - vector visited(V, 0), Wmat(N, 0), latt(N, 1), Bmat(N, 0), clusstats0(V / 2, 0), clusstats1(V / 2, 0); - + vector visited(V, 0), latt(N, 1), clusstats0(V / 2, 0), clusstats1(V / 2, 0); + vector Bmat(N, 0), Wmat(N, 0); /* ====================== CREATING EXISTANCE MATRIX (Exmat)============= */ @@ -52,18 +51,18 @@ int main(void) { /* =================== LOOP TO ITERATE OVER RANGE OF DELTA ============= */ - for (int del = del_beg; del <= del_end; del += del_inc) + for (float del = del_beg; del <= del_end; del += del_inc) { //open - cout << "\ndEL: " << float(del) / 10 << tab; - - + cout << "\ndEL: " << del << tab; + /* =========================== BETA MATRIX (Bmat)======================= */ - //create_Bmat_bimodal(Bmat); // UNCOMMENT FOR BIMODAL DISTRIBUTION - create_Bmat_gaussian(Bmat,del); - //cout << "Bmat created" << endl; - + create_Bmat_bimodal(Bmat,del); // UNCOMMENT FOR BIMODAL DISTRIBUTION + //create_Bmat_gaussian(Bmat,del); // UNCOMMENT FOR GAUSSIAN DISTRIBUTION + cout << "Bmat created" << endl; + //printMatrix(Bmat, N); + savedata(Bmat,l,del,"Phi"); create_Wmat(Wmat, CapacityMat, Bmat, del); @@ -71,8 +70,8 @@ int main(void) { create_Augumented_CapacityMat(Wmat, CapacityMat); - t1 = time(&time_1); /* get current time;*/ - + t1 = long(time(&time_1)); /* get current time;*/ + cout << "\ntic toc"; /*================================================================================================*/ /* ladies and gentlemen its honour to present you the most important stuff in this awesome code */ /* ===================== CALLING PUSH RELABEL(CapacityMat)======================================= */ @@ -80,7 +79,7 @@ int main(void) { pushRelabel(CapacityMat, flow, 0, V - 1); /*====================================================================================*/ - t2 = time(&time_2); /* get current time;*/ + t2 = long(time(&time_2)); /* get current time;*/ /* ====================== CREATE RESIDUAL GRAPH ================== */ create_Residual_graph(CapacityMat, flow); @@ -91,7 +90,8 @@ int main(void) { /* ================= DEPTH FIRST SEARCH ON FLOW ================== */ dfs(flow, 0, visited); - + savedata(visited, l, del, "Si"); + //printMatrix(visited, V); /* ============ CREATE AGUMENTED MATRIX AROUND LATTICE =========== */ createAgumentedMatrix(sqlat0, sqlat1, visited); diff --git a/clustering.cpp b/clustering.cpp index a4f27ef..aa44dce 100644 --- a/clustering.cpp +++ b/clustering.cpp @@ -4,7 +4,7 @@ //* //* A DFS based function to find all reachable vertices from s. //*/ -void dfs(std::vector >& F, long s, std::vector & visited) +void dfs(std::vector >& F, long s, std::vector & visited) { visited[s] = true; for (long i = 0; i < V; i++) @@ -182,14 +182,16 @@ float rms_mag(std::vector & visited) { long i = 0,sum=0; float rmsmag; - for (i = 0; i < visited.size(); i++) + // i not eq to 0 because 0 is source + // i not eq to n because n is sink + for (i = 1; i < visited.size()-1; i++) { if (visited[i] == 1) { sum++; } else { sum--; } } // m = sum(Si) / N; - rmsmag = float(sum) / float(visited.size()); + rmsmag = float(sum) / float(V); return pow(rmsmag,2) ; -} \ No newline at end of file +} diff --git a/clustering.h b/clustering.h index a4025a3..401858e 100644 --- a/clustering.h +++ b/clustering.h @@ -2,7 +2,7 @@ #include "Headers.h" -void dfs(std::vector >& F, long s, std::vector & visited); +void dfs(std::vector >& F, long s, std::vector & visited); // int cluster(std::vector >& lat, int key, std::vector & clusstats); //