forked from hbarbalho/max_cut
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gerando uma solucao inicial gulosa mas ainda nao aleatoria
- Loading branch information
Showing
21 changed files
with
225 additions
and
12 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src/Edge.d src/Edge.o: ../src/Edge.cpp ../src/Edge.h | ||
|
||
../src/Edge.h: |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
src/GA.d src/GA.o: ../src/GA.cpp ../src/GA.h ../src/Instance.h \ | ||
../src/Edge.h ../src/Solution.h | ||
|
||
../src/GA.h: | ||
|
||
../src/Instance.h: | ||
|
||
../src/Edge.h: | ||
|
||
../src/Solution.h: |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
src/Instance.d src/Instance.o: ../src/Instance.cpp ../src/Instance.h | ||
src/Instance.d src/Instance.o: ../src/Instance.cpp ../src/Instance.h \ | ||
../src/Edge.h | ||
|
||
../src/Instance.h: | ||
|
||
../src/Edge.h: |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
src/Main.d src/Main.o: ../src/Main.cpp ../src/Instance.h | ||
src/Main.d src/Main.o: ../src/Main.cpp ../src/Instance.h ../src/Edge.h \ | ||
../src/GA.h ../src/Solution.h | ||
|
||
../src/Instance.h: | ||
|
||
../src/Edge.h: | ||
|
||
../src/GA.h: | ||
|
||
../src/Solution.h: |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src/Solution.d src/Solution.o: ../src/Solution.cpp ../src/Solution.h | ||
|
||
../src/Solution.h: |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Edge.cpp | ||
* | ||
* Created on: Oct 2, 2011 | ||
* Author: hugo | ||
*/ | ||
|
||
#include "Edge.h" | ||
|
||
Edge::Edge(int _i,int _j,int _cost) { | ||
i = _i; | ||
j = _j; | ||
cost = _cost; | ||
} | ||
|
||
Edge::~Edge() { | ||
// TODO Auto-generated destructor stub | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Edge.h | ||
* | ||
* Created on: Oct 2, 2011 | ||
* Author: hugo | ||
*/ | ||
|
||
#ifndef EDGE_H_ | ||
#define EDGE_H_ | ||
|
||
class Edge { | ||
public: | ||
int i,j,cost; | ||
Edge(int,int,int); | ||
virtual ~Edge(); | ||
}; | ||
|
||
#endif /* EDGE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* GA.cpp | ||
* | ||
* Created on: Oct 2, 2011 | ||
* Author: hugo | ||
*/ | ||
|
||
#include "GA.h" | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
Solution* GA::greedySolution(){ | ||
printf("Solucao inicial\n"); | ||
int *sol = (int*)malloc(sizeof(int)*instance->numVertex()); | ||
for(int i=0;i<instance->numVertex();i++){ | ||
sol[i]=-1; | ||
} | ||
|
||
Edge *edge = instance->bestEdge(); | ||
for(int i=1;edge!=NULL;i++){ | ||
if(sol[edge->i]<0 && sol[edge->j]<0){ | ||
sol[edge->i] = 1; | ||
sol[edge->j] = 0; | ||
}else if(sol[edge->i]<0){ | ||
sol[edge->i] = !sol[edge->j]; | ||
}else{ | ||
sol[edge->j] = !sol[edge->i]; | ||
} | ||
edge = instance->bestEdge(i); | ||
} | ||
Solution *solution = new Solution(sol,instance->numVertex()); | ||
return solution; | ||
} | ||
GA::GA(Instance *_instance) { | ||
cout << "GA"<<endl; | ||
instance = _instance; | ||
Solution *initial = greedySolution(); | ||
initial->print(); | ||
} | ||
|
||
GA::~GA() { | ||
// TODO Auto-generated destructor stub | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* GA.h | ||
* | ||
* Created on: Oct 2, 2011 | ||
* Author: hugo | ||
*/ | ||
|
||
#ifndef GA_H_ | ||
#define GA_H_ | ||
#include "Instance.h" | ||
#include "Solution.h" | ||
|
||
class GA { | ||
private: | ||
Instance *instance; | ||
Solution* greedySolution(); | ||
public: | ||
GA(Instance*); | ||
virtual ~GA(); | ||
}; | ||
|
||
#endif /* GA_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Solution.cpp | ||
* | ||
* Created on: Oct 2, 2011 | ||
* Author: hugo | ||
*/ | ||
|
||
#include "Solution.h" | ||
#include <stdio.h> | ||
|
||
void Solution::print(){ | ||
for(int i=0;i<length;i++) | ||
printf("%d ",vertex[i]); | ||
printf("\n"); | ||
} | ||
Solution::Solution(int *_vertex, int _length) { | ||
vertex = _vertex; | ||
length = _length; | ||
} | ||
|
||
Solution::~Solution() { | ||
// TODO Auto-generated destructor stub | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Solution.h | ||
* | ||
* Created on: Oct 2, 2011 | ||
* Author: hugo | ||
*/ | ||
|
||
#ifndef SOLUTION_H_ | ||
#define SOLUTION_H_ | ||
|
||
class Solution { | ||
public: | ||
int *vertex; | ||
int length; | ||
void print(); | ||
Solution(int*,int); | ||
virtual ~Solution(); | ||
}; | ||
|
||
#endif /* SOLUTION_H_ */ |