Skip to content

Commit 54e8944

Browse files
committed
added class to generate input files for pushonly and CT tests, minimal changes to main to call the functions
1 parent d2608ee commit 54e8944

File tree

10 files changed

+199
-1
lines changed

10 files changed

+199
-1
lines changed

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/CompressedStacks.cpp.iml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
2626
message("inc_dirs = ${inc_dirs}")
2727

2828
# Executable
29-
add_executable(smartstack ${SOURCES})
29+
add_executable(smartstack ${SOURCES} sources/createTestInput.cpp sources/createTestInput.h)

sources/createTestInput.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// Created by yago on 16/06/29.
3+
//
4+
5+
#include "createTestInput.h"
6+
7+
using namespace std;
8+
9+
void createTestInput::createTestInputFiles(int code, string fileName,int n,int p, int min, int max, double prob ) //code: 0 pushOnly test, 1: CT test , prob is the probability to pop
10+
{
11+
12+
string line;
13+
ofstream outfile (fileName.c_str());
14+
srand(time(NULL));
15+
16+
switch(code){
17+
case 0 : // push only test
18+
{
19+
// First write the problem parameters
20+
outfile << n << "," << p << endl;
21+
// now create the actual file
22+
// pairs of elements (x,0 means push ) (0,1) means pop one (-1,-1) means pop the rest of the stack
23+
24+
int i = 0;
25+
while (i < n)
26+
{
27+
int contents, action;
28+
// generate random number
29+
double randomDraw = (double)rand() / RAND_MAX;
30+
31+
//cout<<"randomDraw was "<<randomDraw<<endl;
32+
if (randomDraw > prob)// this element will be pushed
33+
{
34+
contents = min + ((randomDraw)) * (max - min);
35+
action = 0;
36+
}
37+
else {
38+
contents = 0;
39+
action = 1;
40+
}
41+
outfile << contents << "," << action << endl;
42+
i++;
43+
}
44+
outfile << -1 << "," << -1 << endl;
45+
break; //optional
46+
}
47+
case 1 :
48+
{
49+
// First write the problem parameters
50+
outfile << n << "," << p << endl;
51+
52+
// now create the actual file
53+
// pairs of elements (x,0 means push ) (0,y) means pop y times (-1,-1) means pop the rest of the stack
54+
55+
int i = 1;
56+
while (i <= n)
57+
{
58+
bool biggerMultiple=false;
59+
int numPops=0;
60+
int number=i;
61+
62+
int biggest=50;
63+
64+
while(biggest*10<=i) {
65+
biggest = biggest * 10;
66+
}
67+
68+
while(biggest>50&&!biggerMultiple) {
69+
if (i % biggest == 0) {
70+
numPops = biggest * 0.45;
71+
biggerMultiple = true;
72+
number=0;
73+
}
74+
else {
75+
biggest = biggest / 10;
76+
}
77+
}
78+
if (i%50==0 && !biggerMultiple ) {
79+
number=0;
80+
numPops = 25;
81+
}
82+
outfile << number << "," << numPops << endl;
83+
i++;
84+
}
85+
86+
87+
break; //optional
88+
}
89+
default : //Optional
90+
{throw (" createTestInput::createTestInputFiles WRONG CODE ");}
91+
}
92+
93+
outfile.close();
94+
95+
96+
97+
98+
99+
}

sources/createTestInput.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Created by yago on 16/06/29.
3+
//
4+
5+
#include <iostream>
6+
#include <fstream>
7+
#include <sstream>
8+
#include <string>
9+
10+
11+
12+
#ifndef SMARTSTACK_CREATETESTINPUT_H
13+
#define SMARTSTACK_CREATETESTINPUT_H
14+
15+
16+
class createTestInput {
17+
18+
19+
public:
20+
createTestInput() { }
21+
22+
void createTestInputFiles(int code, std::string fileName,int n,int p, int min=0, int max=100, double prob=0);
23+
24+
};
25+
26+
27+
#endif //SMARTSTACK_CREATETESTINPUT_H

src/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "../include/normalStack.hpp"
55
#include "../include/compressedStack.hpp"
66
#include "../include/problem.hpp"
7+
#include "../sources/createTestInput.h"
78
#include <string>
89

910
// Test Signature
@@ -72,5 +73,11 @@ int main(int argc, char const *argv[]) {
7273
testData();
7374
testNormalStack();
7475
testCompressedStack();
76+
77+
createTestInput ct=createTestInput();
78+
ct.createTestInputFiles(0,"/home/yago/code/CompressedStacks.cpp/instances/pushOnlyInput.csv",1000,3, 5, 100, 0.2 );
79+
ct.createTestInputFiles(1,"/home/yago/code/CompressedStacks.cpp/instances/CTInput.csv",1000,3);
80+
81+
7582
return 0;
7683
}

0 commit comments

Comments
 (0)