@@ -13,11 +13,12 @@ void createTestInput::createTestInputFiles(int code, string fileName,int n,int p
1313 ofstream outfile (fileName.c_str ());
1414 srand (time (NULL ));
1515
16+ // First write the problem parameters
17+ outfile << n << " ," << p << endl;
18+
1619 switch (code){
1720 case 0 : // push only test
1821 {
19- // First write the problem parameters
20- outfile << n << " ," << p << endl;
2122 // now create the actual file
2223 // pairs of elements (x,0 means push ) (0,1) means pop one (-1,-1) means pop the rest of the stack
2324
@@ -42,13 +43,10 @@ void createTestInput::createTestInputFiles(int code, string fileName,int n,int p
4243 i++;
4344 }
4445 outfile << -1 << " ," << -1 << endl;
45- break ; // optional
46+ break ;
4647 }
4748 case 1 :
4849 {
49- // First write the problem parameters
50- outfile << n << " ," << p << endl;
51-
5250 // now create the actual file
5351 // pairs of elements (x,0 means push ) (0,y) means pop y times (-1,-1) means pop the rest of the stack
5452
@@ -82,11 +80,55 @@ void createTestInput::createTestInputFiles(int code, string fileName,int n,int p
8280 outfile << number << " ," << numPops << endl;
8381 i++;
8482 }
83+ break ;
84+ }
85+ case 2 :
86+ {
87+ // now create the actual file
88+ // pairs of elements (x,0 means push ) (0,1) means pop one (-1,-1) means pop the rest of the stack
89+
90+ std::vector<Point2D> pointsToSort = vector<Point2D>();
91+
92+ int i = 0 ;
93+ while (i < n) {
94+
95+ // create output for the convex hull problem.
96+ // in this case, max and min stand for the maximum and minimum values of x and y
97+ // generate a random point in the (min,max)2 range
98+
99+ double randomx = (double ) rand () / RAND_MAX;
100+ randomx=min+(max-min)*randomx;
101+ double randomy = (double ) rand () / RAND_MAX;
102+ randomy=min+(max-min)*randomy;
103+
104+ // cout<<"generated point "<<randomx<<" "<<randomy<<" "<<pointsToSort.size()<<endl;
105+
106+ pointsToSort.push_back (Point2D (randomx,randomy));
107+ i++;
108+ }
109+
110+
111+ // sort the vector
112+ std::sort (pointsToSort.begin (),pointsToSort.end ());
113+
114+
115+
116+ // add first the point (min,min)
117+ outfile << min << " ," << min << endl;
118+
119+ // add the sorted points
120+ for (int i=0 ;i<pointsToSort.size ();i++)
121+ {
122+ outfile << pointsToSort[i].GetX () << " ," << pointsToSort[i].GetY () << endl;
123+ }
124+
125+ // add finally (max,min)
126+ outfile << max << " ," << min << endl;
85127
86128
87- break ; // optional
129+ break ;
88130 }
89- default : // Optional
131+ default : // Optional
90132 {throw (" createTestInput::createTestInputFiles WRONG CODE " );}
91133 }
92134
0 commit comments