Skip to content

Commit 2290f4f

Browse files
committed
yago puysh des13
1 parent 51866c9 commit 2290f4f

16 files changed

+262
-38
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ file(GLOB SOURCES "examples/convexhull/convexHull64.cpp")
6161
add_executable(convexhull64 ${SOURCES})
6262
file(GLOB SOURCES "examples/convexhull/convexHullExtras.cpp")
6363
add_executable(convexhullextras ${SOURCES})
64+
file(GLOB SOURCES "examples/convexhull/generateInputConvexHull.cpp")
65+
add_executable(generateInputConvexHull ${SOURCES})
66+
6467

6568
# Test Run : 8, 16, 32 or 64 bits and the version with extras
6669
file(GLOB SOURCES "examples/testrun/testrun8.cpp")
@@ -73,6 +76,8 @@ file(GLOB SOURCES "examples/testrun/testrun64.cpp")
7376
add_executable(testrun64 ${SOURCES})
7477
file(GLOB SOURCES "examples/testrun/testrunExtras.cpp")
7578
add_executable(testrunextras ${SOURCES})
79+
file(GLOB SOURCES "examples/testrun/generateInputTestRun.cpp")
80+
add_executable(generateInputTestRun ${SOURCES})
7681

7782

7883
# Description of the different builds

examples/convexhull/convexHull16.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main(int argc, char *argv[]) {
2525

2626
ConvexHull16 stack(filepath);
2727
stack.run();
28-
stack.println();
28+
//stack.println();
2929

3030
return 0;
3131
}

examples/convexhull/convexHull32.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ int main(int argc, char *argv[]) {
2323
// Getting the path of the instance to test
2424
std::string filepath = argv[1];
2525

26+
std::cout<<" aaaa"<<std::endl;
27+
2628
ConvexHull32 stack(filepath);
2729
stack.run();
28-
stack.println();
30+
// stack.println();
2931

3032
return 0;
3133
}

examples/convexhull/convexHull64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main(int argc, char *argv[]) {
2525

2626
ConvexHull64 stack(filepath);
2727
stack.run();
28-
stack.println();
28+
//stack.println();
2929

3030
return 0;
3131
}

examples/convexhull/convexHull8.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main(int argc, char *argv[]) {
2525

2626
ConvexHull8 stack(filepath);
2727
stack.run();
28-
stack.println();
28+
//stack.println();
2929

3030
return 0;
3131
}

examples/convexhull/convexHullExtras.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int main(int argc, char *argv[]) {
4848
case 2: {
4949
usecompressed = true;
5050
useclassic = true;
51+
break;
5152
}
5253
default:
5354
throw "At least one type of stack needs to be selected!!!";
@@ -61,7 +62,7 @@ int main(int argc, char *argv[]) {
6162
stack.printCompare();
6263
} else {
6364
stack.run();
64-
stack.println();
65+
//stack.println();
6566
}
6667
break;
6768
}
@@ -72,7 +73,7 @@ int main(int argc, char *argv[]) {
7273
stack.printCompare();
7374
} else {
7475
stack.run();
75-
stack.println();
76+
//stack.println();
7677
}
7778
break;
7879
}
@@ -83,7 +84,7 @@ int main(int argc, char *argv[]) {
8384
stack.printCompare();
8485
} else {
8586
stack.run();
86-
stack.println();
87+
//stack.println();
8788
}
8889
break;
8990
}
@@ -94,7 +95,7 @@ int main(int argc, char *argv[]) {
9495
stack.printCompare();
9596
} else {
9697
stack.run();
97-
stack.println();
98+
//stack.println();
9899
}
99100
}
100101

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// Created by yago on 16/11/04.
3+
//
4+
5+
#include<string>
6+
#include<iostream>
7+
#include <fstream>
8+
#include <math.h>
9+
#include "include/point2D.hpp"
10+
#include<vector>
11+
#include<algorithm>
12+
13+
using namespace std;
14+
15+
int main(int argc, char *argv[])
16+
{
17+
18+
string fileName=argv[1];
19+
int stacktype=atoi(argv[2]);
20+
std::uint_least64_t n=atoi(argv[3]);
21+
int p=atoi(argv[4]);
22+
int min=0;
23+
if (argc>5) min=atoi(argv[5]);
24+
int max=0;
25+
if (argc>6) max=atoi(argv[6]);
26+
27+
ofstream outfile(fileName.c_str());
28+
srand(time(NULL));
29+
30+
// First write the problem parameters
31+
outfile << "HEADER " << endl;
32+
outfile << "n " << n << endl;
33+
if(stacktype==1)//compressed stack
34+
{
35+
outfile << "p " << p << endl;
36+
outfile << "b " << "2" << endl; // buffer for the CH problem
37+
}
38+
outfile << "/HEADER " << endl;
39+
40+
41+
std::vector<Point2D> pointsToSort = vector<Point2D>();
42+
43+
int i = 0;
44+
while (i < n) {
45+
46+
// create output for the convex hull problem.
47+
// in this case, max and min stand for the maximum and minimum values of x
48+
// and y
49+
// generate a random point in the (min,max)2 range
50+
51+
double randomx = (double)rand() / RAND_MAX;
52+
randomx = min + (max - min) * randomx;
53+
double randomy = (double)rand() / RAND_MAX;
54+
randomy = min + (max - min) * randomy;
55+
56+
// cout<<"generated point "<<randomx<<" "<<randomy<<"
57+
// "<<pointsToSort.size()<<endl;
58+
59+
pointsToSort.push_back(Point2D(randomx, randomy));
60+
i++;
61+
}
62+
63+
// sort the vector
64+
std::sort(pointsToSort.begin(), pointsToSort.end());
65+
66+
// add first the point (min,min)
67+
outfile << min << "," << min << endl;
68+
69+
// add the sorted points
70+
for (int j = 0; j < (int)pointsToSort.size(); j++) {
71+
outfile << pointsToSort[j].GetX() << "," << pointsToSort[j].GetY()
72+
<< endl;
73+
}
74+
75+
// add finally (max,min)
76+
outfile << max << "," << min << endl;
77+
78+
79+
80+
outfile.close();
81+
82+
return 0;
83+
}

examples/convexhull/include/convexHull.hpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include "../../../include/stackAlgo.hpp"
99
#include "point2D.hpp"
1010

11+
12+
double pops=0;
13+
double total=0;
14+
1115
/*==============================================================================
1216
Empty type for the context (empty for the Convex Hull problem)
1317
==============================================================================*/
@@ -61,7 +65,7 @@ Point2D ConvexHull<I>::readInput(std::vector<std::string> line) {
6165

6266
Point2D p(x, y);
6367

64-
std::cout << "I JUST READ " << p << std::endl;
68+
//std::cout << "I JUST READ " << p << std::endl;
6569
return p;
6670
}
6771

@@ -70,7 +74,8 @@ template <class I> std::shared_ptr<emptyContext> ConvexHull<I>::initStack() {
7074
std::cout << "going to read two values " << std::endl;
7175

7276
// first, read and push two values
73-
StackAlgo<emptyContext, Point2D, I>::readPush(2);
77+
StackAlgo<emptyContext, Point2D, I>::readPush(1);
78+
StackAlgo<emptyContext, Point2D, I>::readPush(1);
7479

7580
std::cout << "done reading two values " << std::endl;
7681

@@ -81,22 +86,24 @@ template <class I> std::shared_ptr<emptyContext> ConvexHull<I>::initStack() {
8186

8287
template <class I> bool ConvexHull<I>::popCondition(Point2D last) {
8388
Point2D minus1, minus2;
84-
89+
total++;
8590
std::cout << last << " <<<< pop condition enter " << std::endl;
91+
StackAlgo<emptyContext, Point2D, I>::println();
8692

8793
// read the two previous elements
8894
minus1 = StackAlgo<emptyContext, Point2D, I>::top(1).getData();
8995
minus2 = StackAlgo<emptyContext, Point2D, I>::top(2).getData();
9096

91-
std::cout << last << " <<<< pop condition read two before " << minus1
92-
<< minus2 << std::endl;
97+
std::cout << last << " <<<< pop condition read two before " << minus2<< minus1 << std::endl;
9398

94-
if (Point2D::orientation(minus2, minus1, last) == 2) {
95-
std::cout << last << " <<<< pop condition returning true " << std::endl;
99+
if (Point2D::orientation(minus2, minus1, last) == 1) {
100+
pops++;
101+
std::cout << last << " <<<< pop condition returning true "<<pops/total<<" tot "<<total << std::endl;
96102

97103
return true;
98104
}
99-
std::cout << last << " <<<< pop condition returning false " << std::endl;
105+
std::cout << last << " <<<< pop condition returning false "<<pops/total<<" tot "<<total << std::endl;
106+
100107

101108
return false;
102109
}
@@ -115,8 +122,7 @@ template <class I>
115122
void ConvexHull<I>::prePush(Data<emptyContext, Point2D, I> elt) {}
116123
template <class I>
117124
void ConvexHull<I>::postPush(Data<emptyContext, Point2D, I> elt) {
118-
std::cout << "ConvexHullStackAlgo::pushAction Nothing to see here "
119-
<< elt.getData() << std::endl;
125+
std::cout << "ConvexHullStackAlgo::pushAction Nothing to see here " << elt.getData() << std::endl;
120126
}
121127
template <class I> void ConvexHull<I>::noPush(Point2D data) {}
122128

examples/convexhull/include/convexHullExtras.hpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@ Point2D ConvexHullExtras<I>::readInput(std::vector<std::string> line) {
6363

6464
Point2D p(x, y);
6565

66-
std::cout << "I JUST READ " << p << std::endl;
66+
//std::cout << "I JUST READ " << p << std::endl;
6767

6868
return p;
6969
}
7070

7171
template <class I>
7272
std::shared_ptr<emptyContext> ConvexHullExtras<I>::initStack() {
73-
std::cout << "going to read two values " << std::endl;
73+
// std::cout << "going to read two values " << std::endl;
7474

7575
// first, read and push two values
7676
StackAlgoExtras<emptyContext, Point2D, I>::readPush(2);
7777

7878
// StackAlgoExtras<emptyContext, Point2D, I>::printCompare();
7979

80-
std::cout << "done reading two values " << std::endl;
80+
//std::cout << "done reading two values " << std::endl;
8181
// then initialize context (which in this case is NULL everything
8282
std::shared_ptr<emptyContext> context;
8383
return context;
@@ -86,42 +86,40 @@ std::shared_ptr<emptyContext> ConvexHullExtras<I>::initStack() {
8686
template <class I> bool ConvexHullExtras<I>::popCondition(Point2D last) {
8787
Point2D minus1, minus2;
8888

89-
std::cout << last << " <<<< pop condition enter " << std::endl;
89+
// std::cout << last << " <<<< pop condition enter " << std::endl;
9090

9191
// read the two previous elements
9292
minus1 = StackAlgoExtras<emptyContext, Point2D, I>::top(1).getData();
9393
minus2 = StackAlgoExtras<emptyContext, Point2D, I>::top(2).getData();
9494

95-
std::cout << last << " <<<< pop condition read two before " << minus1
96-
<< minus2 << std::endl;
95+
// std::cout << last << " <<<< pop condition read two before " << minus1<< minus2 << std::endl;
9796

9897
if (Point2D::orientation(minus2, minus1, last) == 2) {
99-
std::cout << last << " <<<< pop condition returning true " << std::endl;
98+
// std::cout << last << " <<<< pop condition returning true " << std::endl;
10099

101100
return true;
102101
}
103-
std::cout << last << " <<<< pop condition returning false " << std::endl;
102+
// std::cout << last << " <<<< pop condition returning false " << std::endl;
104103

105104
return false;
106105
}
107106
template <class I> void ConvexHullExtras<I>::prePop(Point2D data) {}
108107
template <class I>
109108
void ConvexHullExtras<I>::postPop(Point2D data,
110109
Data<emptyContext, Point2D, I> elt) {
111-
std::cout << elt.getData() << " <<<< Pop!" << std::endl;
110+
// std::cout << elt.getData() << " <<<< Pop!" << std::endl;
112111
}
113112
template <class I> void ConvexHullExtras<I>::noPop(Point2D data) {}
114113

115114
template <class I> bool ConvexHullExtras<I>::pushCondition(Point2D data) {
116-
std::cout << data << " <<<< push condition returning true " << std::endl;
115+
// std::cout << data << " <<<< push condition returning true " << std::endl;
117116
return true;
118117
}
119118
template <class I>
120119
void ConvexHullExtras<I>::prePush(Data<emptyContext, Point2D, I> elt) {}
121120
template <class I>
122121
void ConvexHullExtras<I>::postPush(Data<emptyContext, Point2D, I> elt) {
123-
std::cout << "ConvexHullStackAlgo::pushAction Nothing to see here "
124-
<< elt.getData() << std::endl;
122+
//std::cout << "ConvexHullStackAlgo::pushAction Nothing to see here " << elt.getData() << std::endl;
125123
}
126124
template <class I> void ConvexHullExtras<I>::noPush(Point2D data) {}
127125

examples/convexhull/include/point2D.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ double Point2D::GetY() const { return y; }
9090
// 2 --> Counterclockwise
9191
// taken from http://www.geeksforgeeks.org/orientation-3-ordered-points/
9292
int Point2D::orientation(Point2D p1, Point2D p2, Point2D p3) {
93+
9394
int val = (p2.y - p1.y) * (p3.x - p2.x) - (p2.x - p1.x) * (p3.y - p2.y);
9495

96+
std::cout<<"ORIENTATION BETWEEN "<<p1<<" "<<p2<<" "<<p3<<" is:"<<((val > 0) ? 1 : 2)<<std::endl;
97+
9598
if (val == 0)
9699
return 0; // colinear
97100
return (val > 0) ? 1 : 2; // clock or counterclock wise

0 commit comments

Comments
 (0)