Skip to content

Commit

Permalink
Updated instances generators
Browse files Browse the repository at this point in the history
  • Loading branch information
nicill authored and Azzaare committed May 30, 2017
1 parent e36ed1f commit bb8607f
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 53 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# cmake.exe .. -G "Visual Studio 12 2013"
# cmake.exe .. -G "Visual Studio 13 2014"
# cmake.exe .. -G "Visual Studio 14 2015"
# cmake.exe .. -G "Visual Studio 15 2017"


# Recent version of CMake required
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ This project is far from being complete and would benefit greatly from future co


## Credits
Although this project is a joint work, based on the theoretical work in [Barba *et al.*](https://arxiv.org/abs/1208.3663), credits belong to specific authors for part of the implementation. The work covering the implementation of the Stack Algorithm framework, the Comrpessed Stack structure and extras functionalities (```include``` and ```extras``` repositories) has been done by [Jean-Francois Baffier](https://github.com/Azzaarehttps://github.com/Azzaare). All the examples and their generating algorithms, along with all the test have been implemented by [Yago Diez](https://github.com/nicill).
Although this project is a joint work, based on the theoretical work in [Barba *et al.*](https://arxiv.org/abs/1208.3663), credits belong to specific authors for part of the implementation. The work covering the implementation of the Stack Algorithm framework, the Compressed Stack structure and extras functionalities (```include``` and ```extras``` repositories) has been done by [Jean-Francois Baffier](https://github.com/Azzaarehttps://github.com/Azzaare). All the examples and their generating algorithms, along with all the test have been implemented by [Yago Diez](https://github.com/nicill).

## License
This project is an open source software under the MIT license. Please check the ```LICENSE``` file for further information.
134 changes: 92 additions & 42 deletions examples/testrun/generateInputTestRun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using namespace std;

int main(int argc, char *argv[]) {


string fileName = argv[1];
int code = atoi(argv[2]);
int stacktype = atoi(argv[3]);
Expand All @@ -30,9 +31,7 @@ int main(int argc, char *argv[]) {
// prob is the
// probability to pop

// cout<<":::::::::::::::::::::::::::::::::::::::::::: Going to create file
// with size "<<n<<" the size of an int happens to be "<<sizeof(int)<<" and
// the maximum "<<INT64_MAX<<endl;
//cout<<":::::::::::::::::::::::::::::::::::::::::::: Going to create file with size "<<n<<" the size of an int happens to be "<<sizeof(int)<<" and the maximum "<<INT64_MAX<<endl;

ofstream outfile(fileName.c_str());
srand(time(NULL));
Expand All @@ -46,8 +45,9 @@ int main(int argc, char *argv[]) {
}
outfile << "/HEADER " << endl;


switch (code) {
case 0: // push only test
case 1: // push only test
{
// now create the actual file
// pairs of elements (x,0 means push ) (0,1) means pop one (-1,-1) means pop
Expand All @@ -66,6 +66,7 @@ int main(int argc, char *argv[]) {
action = 0;
} else {
contents = 0;
// contents = 17; // now I also push myself and then I will pop myself
action = 1;
}
outfile << contents << "," << action << endl;
Expand All @@ -74,48 +75,97 @@ int main(int argc, char *argv[]) {
outfile << -1 << "," << -1 << endl;
break;
}
case 1: {
// now create the actual file
// pairs of elements (x,0 means push ) (0,y) means pop y times (-1,-1) means
// pop the rest of the stack

std::uint_least64_t i = 1;
while (i <= n) {
bool biggerMultiple = false;
int numPops = 0;
int number = i;

std::uint_least64_t biggest = 50;
int power = 1;

while (biggest * 10 <= i) {
biggest = biggest * 10;
power++;
}

while (biggest > 50) {
if (i % biggest == 0) {
numPops = numPops + pow(5, power + 1);
biggerMultiple = true;
number = 0;
// cerr<<"HEY!!!!!!!!!!!!!!!!!!! setting "<<numPops<<" pops for i =
// "<<i<<" biggest is "<<biggest<<" and power is "<<power<<endl;
}
biggest = biggest / 10;
power--;
}

if (i % 50 == 0 /*&& !biggerMultiple*/) {
number = 0;
numPops = numPops + 25;
case 2: { // christmas tree
// now create the actual file
// pairs of elements (x,0 means push ) (0,y) means pop y times (-1,-1) means
// pop the rest of the stack

std::uint_least64_t i = 1;
while (i <= n) {
bool biggerMultiple = false;
int numPops = 0;
int number = i;

std::uint_least64_t biggest = 50;
std::uint_least64_t power = 1;

while (biggest * 10 <= i) {
biggest = biggest * 10;
power++;
}

while (biggest > 50) {
if (i % biggest == 0) {
numPops = numPops + pow(5, (float)power + 1);
biggerMultiple = true;
number = 0;
// cerr<<"HEY!!!!!!!!!!!!!!!!!!! setting "<<numPops<<" pops for i =
// "<<i<<" biggest is "<<biggest<<" and power is "<<power<<endl;
}
biggest = biggest / 10;
power--;
}

if (i % 50 == 0 /*&& !biggerMultiple*/) {
number = 0;
numPops = numPops + 25;
}
outfile << number << "," << numPops << endl;

i++;
}
outfile << number << "," << numPops << endl;
i++;
}
break;
break;
}
case 3: { // tunned christmas tree
// pairs of elements (x,0 means push ) (0,y) means pop y times (-1,-1) means
// pop the rest of the stack

std::uint_least64_t i = 1;
while (i <= n) {
bool biggerMultiple = false;
int numPops = 0;
int number = i;

std::uint_least64_t cycle = atoi(argv[6]);
std::uint_least64_t step = atoi(argv[7]);
std::uint_least64_t pops = atoi(argv[8]);

std::uint_least64_t biggest = cycle;
std::uint_least64_t base = cycle/step;
int power = 1;

while (biggest * step <= i) {
biggest = biggest * step;
power++;
}

while (biggest > cycle) {
if (i % biggest == 0) {
numPops = numPops + pow(pops, (float) power );
biggerMultiple = true;
number = 0;
// cerr<<"HEY!!!!!!!!!!!!!!!!!!! setting "<<numPops<<" pops for i =
// "<<i<<" biggest is "<<biggest<<" and power is "<<power<<endl;
}
biggest = biggest / step;
power--;
}

if (i % cycle == 0 /*&& !biggerMultiple*/) {
number = 0;
numPops = numPops + pops;
}
if(number==0) outfile<< i << "," << 0 << endl;
outfile << number << "," << numPops << endl;
//if(number==0) cout<< i << "," << 0 << endl;
//cout<< number << "," << numPops << endl;
i++;
}
break;
}
default: // Optional
{
cout<<"createTestInput::createTestInputFiles WRONG CODE "<<code<<endl;
throw(" createTestInput::createTestInputFiles WRONG CODE ");
}
}
Expand Down
14 changes: 7 additions & 7 deletions examples/testrun/testrunExtras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ using TestExtras64 = TestExtras<std::uint_least64_t>;
How to use
* argv[1] is the file name
* argv[2] is the code of what is to be done
* 0 is a convex hull problem with a compressed stack (with extras)
* 1 is a convex hull problem with a classical stack
* 2 is a convex hull problem with both stacks comparison (check
* 0 is a testrun problem with a compressed stack (with extras)
* 1 is a testrun problem with a classical stack
* 2 is a testrun problem with both stacks comparison (check
errors)
* argv[3] is the code for the integer size
* 8 is for 8 bits integer (or smallest size handling 8 bits)
Expand Down Expand Up @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) {
stack.printCompare();
} else {
stack.run();
//stack.println();
// stack.println();
}
break;
}
Expand All @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) {
stack.printCompare();
} else {
stack.run();
// stack.println();
// stack.println();
}
break;
}
Expand All @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) {
stack.printCompare();
} else {
stack.run();
//stack.println();
// stack.println();
}
break;
}
Expand All @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) {
stack.printCompare();
} else {
stack.run();
// stack.println();
// stack.println();
}
}
return 0;
Expand Down
6 changes: 6 additions & 0 deletions extras/classicStack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ClassicStack : public Stack<T, D, I> {
Block<T, D, I> getFirstBlock();
I getBufferSize();
I getBufferLength();
std::vector<int> getReconstructions();
};

/*==============================================================================
Expand Down Expand Up @@ -129,6 +130,11 @@ Block<T, D, I> ClassicStack<T, D, I>::getFirstBlock() {
return block;
}

template <class T, class D, class I>
std::vector<int> ClassicStack<T, D, I>::getReconstructions() {
return std::vector<int>(0);
}

/*==============================================================================
IO : toString
==============================================================================*/
Expand Down
4 changes: 4 additions & 0 deletions extras/stackAlgoExtras.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ void StackAlgoExtras<T, D, I>::readPushCompare(I iter) {
template <class T, class D, class I>
void StackAlgoExtras<T, D, I>::pushStepCompare(D data) {
if (pushCondition(data)) {
StackAlgo<T, D, I>::mCountPushes++;
StackAlgo<T, D, I>::mMaxItems = std::max(StackAlgo<T, D, I>::mMaxItems,
StackAlgo<T, D, I>::countItems());
Data<T, D, I> elt(StackAlgo<T, D, I>::mIndex, data);
prePush(elt);
StackAlgo<T, D, I>::push(elt);
Expand All @@ -141,6 +144,7 @@ template <class T, class D, class I>
void StackAlgoExtras<T, D, I>::popLoopCompare(D data) {
while (!StackAlgo<T, D, I>::emptystack()) {
if (popCondition(data)) {
StackAlgo<T, D, I>::mCountPops++;
prePop(data);
Data<T, D, I> elt = StackAlgo<T, D, I>::pop();
Data<T, D, I> eltNormal = mClassicStack->pop();
Expand Down
6 changes: 6 additions & 0 deletions include/compressedStack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class CompressedStack : public Stack<T, D, I> {
SPData<T, D, I> getExplicitData(I k);
Level<T, D, I> getSmartCompress(std::intmax_t lvl);
Block<T, D, I> getBottomBlock();
std::vector<int> getReconstructions();

// Structure constraints
I mSize; // (Expected) size of the input in #elements
Expand Down Expand Up @@ -469,6 +470,11 @@ I CompressedStack<T, D, I>::getBufferLength() {
return mBuffer.mExplicit.size();
}

template <class T, class D, class I>
std::vector<int> CompressedStack<T, D, I>::getReconstructions() {
return mReconstructions;
}

/*==============================================================================
IO : toString
==============================================================================*/
Expand Down
1 change: 1 addition & 0 deletions include/stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ template <class T, class D, class I> class Stack {
virtual Block<T, D, I> getFirstBlock() = 0;
virtual I getBufferSize() = 0;
virtual I getBufferLength() = 0;
virtual std::vector<int> getReconstructions() = 0;

// Setters
virtual void setContext(std::shared_ptr<T> context) = 0;
Expand Down
41 changes: 38 additions & 3 deletions include/stackAlgo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,27 @@ template <class T, class D, class I> class StackAlgo {

// Getters
T getContext();

I getIndex();
I getMaxItems();
I getPushes();
I getPops();
std::vector<int> getReconstructions();

// IO
std::string toString();
void print();
void println();
I countItems();
void readPush(I iter = 1);

// protected:
void initStackIntern();
std::vector<std::string> readLine();
std::vector<std::string> readHeader();
I mIndex;
I mMaxItems;
I mCountPops;
I mCountPushes;

// private:
// Input/Ouput
Expand Down Expand Up @@ -95,7 +102,8 @@ template <class T, class D, class I> class StackAlgo {
==============================================================================*/
template <class T, class D, class I>
StackAlgo<T, D, I>::StackAlgo(std::string fileName, bool usecompressed)
: mIndex(0), mContext(nullptr) {
: mIndex(0), mMaxItems(0), mCountPops(0), mCountPushes(0),
mContext(nullptr) {
mInput.open(fileName, std::ifstream::in);

std::vector<std::string> parameters = readHeader();
Expand Down Expand Up @@ -132,7 +140,10 @@ template <class T, class D, class I>
std::string StackAlgo<T, D, I>::toString() {
std::string str;
str = "Instance with an actual index of " + std::to_string(mIndex);
str += ", with a stack of type\n";
str += ", with " + std::to_string(countItems()) + " elements (";
str += std::to_string(getPushes()) + " - " + std::to_string(getPops()) + ")";
str += ", a maximum size of " + std::to_string(getMaxItems()) + " elements";
str += ", and a stack of type\n";
str += mStack->toString();
return str;
}
Expand Down Expand Up @@ -203,6 +214,7 @@ template <class T, class D, class I> void StackAlgo<T, D, I>::readPush(I iter) {
template <class T, class D, class I> void StackAlgo<T, D, I>::popLoop(D data) {
while (!emptystack()) {
if (popCondition(data)) {
mCountPops++;
prePop(data);
Data<T, D, I> elt = pop();
postPop(data, elt);
Expand All @@ -215,6 +227,8 @@ template <class T, class D, class I> void StackAlgo<T, D, I>::popLoop(D data) {

template <class T, class D, class I> void StackAlgo<T, D, I>::pushStep(D data) {
if (pushCondition(data)) {
mCountPushes++;
mMaxItems = std::max(mMaxItems, countItems());
Data<T, D, I> elt(mIndex, data);
prePush(elt);
push(elt);
Expand Down Expand Up @@ -316,4 +330,25 @@ template <class T, class D, class I> I StackAlgo<T, D, I>::getIndex() {
return mIndex;
}

template <class T, class D, class I> I StackAlgo<T, D, I>::getPops() {
return mCountPops;
}

template <class T, class D, class I> I StackAlgo<T, D, I>::getPushes() {
return mCountPushes;
}

template <class T, class D, class I> I StackAlgo<T, D, I>::countItems() {
return mCountPushes - mCountPops;
}

template <class T, class D, class I> I StackAlgo<T, D, I>::getMaxItems() {
return mMaxItems;
}

template <class T, class D, class I>
std::vector<int> StackAlgo<T, D, I>::getReconstructions() {
return mStack.getReconstructions();
}

#endif /* STACKALGO */

0 comments on commit bb8607f

Please sign in to comment.