Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: lvirgili/dag_modification
base: 3c48536eb4
...
head fork: lvirgili/dag_modification
compare: 3e5a1c075a
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
27 codigo/graph.c
@@ -1,4 +1,17 @@
#include "graph.h"
+static void calculate_weights(int **G, int ntasks) {
+ int i, j;
+ path_weight = (int *)malloc(sizeof(int) * (ntasks * pathid));
+ for (i = 0; i < pathid; ++i) {
+ path_weight[i] = 0;
+ for (j = 0; j < ntasks; ++j) {
+ path_weight[i] += G[paths[i][j]][paths[i][j+1]];
+ if (paths[i][j+1] == ntasks-1) {
+ break;
+ }
+ }
+ }
+}
static void find_path(int **G, int ntasks, int vertex, int pos, int *curr) {
int i, flag = 0;
@@ -18,20 +31,6 @@ static void find_path(int **G, int ntasks, int vertex, int pos, int *curr) {
}
}
-static void calculate_weights(int **G, int ntasks) {
- int i, j;
- path_weight = (int *)malloc(sizeof(int) * (ntasks * pathid));
- for (i = 0; i < pathid; ++i) {
- path_weight[i] = 0;
- for (j = 0; j < ntasks; ++j) {
- path_weight[i] += G[paths[i][j]][paths[i][j+1]];
- if (paths[i][j+1] == ntasks-1) {
- break;
- }
- }
- }
-}
-
static void gen_paths(int **G, int ntasks) {
int i, j, source;
int *curr;
View
2  src/Makefile
@@ -1,5 +1,5 @@
CC = g++
-FLAGS = -std=c++0x -Wall
+FLAGS = -std=c++0x -Wall -Wfatal-errors
LMATH = -lm
OBJS = dag.o main.o
View
40 src/dag.cpp
@@ -1,10 +1,10 @@
#include "dag.hpp"
-int app_dag::ntasks() {
+int app_dag::ntasks() const {
return _ntasks;
}
-int app_dag::nvm() {
+int app_dag::nvm() const {
return _nvm;
}
@@ -34,6 +34,7 @@ app_dag::app_dag(const char *filename) {
++_nvm;
}
}
+ getline(f,s);
_B = new int *[_ntasks];
for (int i = 0; i < _ntasks; ++i) {
_B[i] = new int[_ntasks];
@@ -43,6 +44,7 @@ app_dag::app_dag(const char *filename) {
for (int j = 0; j < _ntasks; ++j) {
f >> _B[i][j];
}
+ getline(f,s);
}
return;
} else {
@@ -52,9 +54,41 @@ app_dag::app_dag(const char *filename) {
}
app_dag::~app_dag() {
- delete[] _S;
for (int i = 0; i < _ntasks; ++i) {
delete[] _B[i];
}
delete[] _B;
+ delete[] _S;
+}
+
+void app_dag::find_path(int cur_vertex, vector<int>& curr) {
+ curr.push_back(cur_vertex);
+ if (cur_vertex == _ntasks-1 && curr[0] == 0) {
+ _paths.insert(curr);
+ curr.clear();
+ return;
+ }
+ for (int i = cur_vertex+1; i < _ntasks; ++i) {
+ if (_B[cur_vertex][i] > 0) {
+ find_path(i, curr);
+ }
+ }
+}
+
+void app_dag::gen_paths() {
+ for (int i = 1; i < _ntasks-1; ++i) {
+ vector<int> curr;
+ curr.push_back(0);
+ if (_B[0][i] > 0) {
+ find_path(i, curr);
+ }
+ }
+ set<vector<int> >::iterator it;
+ for (it = _paths.begin(); it != _paths.end(); ++it) {
+ vector<int> aux = *it;
+ for (unsigned j = 0; j < aux.size(); ++j) {
+ cout << aux[j] << ' ';
+ }
+ cout << endl;
+ }
}
View
18 src/dag.hpp
@@ -3,24 +3,28 @@
#include <iostream>
#include <fstream>
#include <string>
-#include <sstream>
#include <set>
+#include <vector>
using namespace std;
class app_dag {
private:
- int _ntasks; //Number of tasks.
- int _nvm; //Number of VMs.
- int *_S; //Software demand of each tasks, denoted by the VM's id.
- int **_B; //Number of bytes transmitted between tasks.
+ int _ntasks; //Number of tasks.
+ int _nvm; //Number of VMs.
+ int *_S; //Software demand of each tasks, denoted by the VM's id.
+ int **_B; //Number of bytes transmitted between tasks.
+ set<vector<int> > _paths;
+
+ void find_path(int cur_vertex, vector<int>& curr);
public:
- int ntasks();
- int nvm();
+ int ntasks() const;
+ int nvm() const;
int S(const int ) const;
int B(const int, const int) const;
app_dag(const char *);
~app_dag();
+ void gen_paths();
};
#endif
View
2  src/main.cpp
@@ -19,6 +19,8 @@ int main(int argc, char **argv) {
}
cout << endl;
}
+ cout << "======\n";
+ G.gen_paths();
return 0;
}

No commit comments for this range

Something went wrong with that request. Please try again.