Skip to content

Commit

Permalink
done for the night
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrush committed Feb 16, 2014
1 parent 75586cb commit 0a0fd9d
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 108 deletions.
10 changes: 5 additions & 5 deletions hw2/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
OTHER_FLAGS=(-std=c++0x)
OTHER_FLAGS= -std=c++0x

all: hw2

hw2: csvparse.o hw2.o
g++ -o hw2 hw2.o csvparse.o
hw2: hw2.o
g++ -o hw2 hw2.o

hw2.o: hw2.cpp
g++ ${OTHER_FLAGS} -c hw2.cpp
hw2.o: hw2.cpp csvparse.o
g++ ${OTHER_FLAGS} -c hw2.cpp csvparse.o

csvparse.o: csvparse.cpp csvparse.hpp
g++ ${OTHER_FLAGS} -c csvparse.cpp
Expand Down
108 changes: 12 additions & 96 deletions hw2/csvparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
#include <iterator>
#include <chrono>

std::vector<mabcb7::Line> parseFile(const std::string filename)
{
std::vector<mabcb7::Line> result;

return result;
}

typedef std::map<std::pair<float,float>, vector<float>> line_map;

line_map parseFile(const char* filename);


vector<float> splitFloat(const string& s, const string& delim) {
vector<float> result;
Expand All @@ -36,31 +35,16 @@ vector<float> splitFloat(const string& s, const string& delim) {
return result;
}

int main(int argc, char* argv[])
line_map parseFile(const char* filename)
{

if (argc != 2)
{
std::cout << "Error incorrect command line arguments. USAGE: ./csvparse <path to file>" << std::endl;
return 0;
}

std::multimap<std::pair<float,float>, vector<float>> mapa; //multimap to hold data
//std::multimap<std::pair<float,float>, vector<float>> mapa; //multimap to hold data
line_map mapa;
int count = 0; //counter for number of lines read and processed
ifstream myfile (argv[1]); //file stream
ifstream myfile (filename); //file stream
string line; //temporary line pointer
float x;
float y;
float xmin; //min and max values
float ymin;
float xmax;
float ymax;
vector<float> min;
vector<float> max;





std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();

Expand All @@ -83,80 +67,12 @@ int main(int argc, char* argv[])

std::cout << "Parsing the file took " << time_span.count() << " seconds." << std::endl;
std::cout << count << " lines were parsed" << std::endl;
count = 1;

start = std::chrono::high_resolution_clock::now();

std::map<std::pair<float,float>, vector<float>>::iterator itr = mapa.begin();
xmin = xmax = itr->first.first;
ymin = ymax = itr->first.second;
//load min and max vectors
for (int i = 0; i < itr->second.size(); ++i)
{
min.push_back(itr->second[i]);
max.push_back(itr->second[i]);
}
itr++;

for (itr; itr !=mapa.end(); ++itr)
{
count++;
if (xmin > itr->first.first)
{
xmin = itr->first.first;
}
if (xmax < itr->first.first)
{
xmax = itr->first.first;
}
if (ymin > itr->first.second)
{
ymin = itr->first.second;
}
if (ymax < itr->first.second)
{
ymax = itr->first.second;
}
vector<float> numbers = itr->second;
for (int j = 0; j < numbers.size(); ++j)
{
if (min[j] > numbers[j])
{
min[j] = numbers[j];
}
if (max[j] < numbers[j])
{
max[j] = numbers[j];
}
}

}

stop = std::chrono::high_resolution_clock::now();
time_span = std::chrono::duration_cast<std::chrono::duration<double> >(stop - start);

std::cout << "Finding the bounding values took " << time_span.count() << " seconds." << std::endl;
std::cout << count << " lines searched" << std::endl;

cout << "X Min: " << xmin << std::endl << "Y Min: " << ymin << std::endl <<"X max: " << xmax << std::endl << "Y Max: " << ymax << std::endl;

cout << "Min Vector: " << min[0];
for (int i = 1; i < min.size(); i++)
{
cout << ", " << min[i];
}
cout << std::endl;

cout << "Max Vector: " << max[0];
for (int i = 1; i < max.size(); i++)
{
cout << ", " << max[i];
}
cout << std::endl;

myfile.close();

return 0;
return mapa;

}



13 changes: 6 additions & 7 deletions hw2/csvparse.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using namespace std;

namespace mabcb7
{
using namespace std;

typedef struct line {
/*
struct line {
int x;
int y;
std::vector<float> points;
} Line;
*/
//typedef std::map<std::pair<float,float>, vector<float>> line;

std::vector<mabcb7::Line> parseFile(const std::string filename);

}

//std::multimap<std::pair<float,float>, vector<float>> mapa;
Binary file added hw2/csvparse.o
Binary file not shown.
Binary file added hw2/hw2
Binary file not shown.
40 changes: 40 additions & 0 deletions hw2/hw2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "csvparse.cpp"
#include "hw2.hpp"

int main(int argc, char* argv[])
{
if (argc != 2)
{
std::cout << "Error incorrect command line arguments. USAGE: ./csvparse <path to file>" << std::endl;
return 0;
}

line_map mapa = parseFile(argv[1]);
line_map::iterator itr = mapa.begin();
std::vector<float> svector {9, 8, 7, 6, 5, 4, 3, 2, 1};
std::vector<result> results;

std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();

for (itr; itr !=mapa.end(); ++itr)
{
results = (circularSubvectorMatch(svector, itr->second, 9, itr->first));
}

sort(results.begin(), results.end());
results.resize(10);

std::chrono::high_resolution_clock::time_point stop = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> time_span = std::chrono::duration_cast<std::chrono::duration<double> >(stop - start);

std::cout << "Swinging through once took: " << time_span.count() << " seconds." << std::endl;

std::vector<result>::iterator it = results.begin();

for (it; it != results.end(); ++ it)
{
cout << it->coord.first << ", " << it->coord.second << " " << it->offset << " " << it->distance << std::endl;
}

return 0;
}
42 changes: 42 additions & 0 deletions hw2/hw2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <math.h>

struct result
{
std::pair<float,float> coord;
int offset;
float distance;

bool operator < (const result& str) const
{
return (distance < str.distance);
}
};

std::vector<result> circularSubvectorMatch(std::vector<float> svector, std::vector<float> cir, int n, std::pair<float, float> coord)
{
int i;
int sizeOfSearch = svector.size();
int sizeOfCircle = cir.size();

int offset;
result temp;
std::vector<result> results;
temp.coord = coord;

for (offset = 0; offset < sizeOfCircle; offset += 5)
{
for (i = offset; i < offset + n; i++)
{
temp.distance += fabs(svector[i % sizeOfSearch] - cir[i % sizeOfCircle]);
//cout << i << " " << offset << ": " << temp.distance << " += | " << svector[i % sizeOfSearch] << " - " << cir[i % sizeOfCircle] << " | " << std::endl;
}

temp.offset = offset;
results.push_back(temp);

}

std::sort(results.begin(), results.end());
results.resize(10);
return results;
}
Binary file added hw2/hw2.o
Binary file not shown.
10 changes: 10 additions & 0 deletions hw2/test.csv

Large diffs are not rendered by default.

0 comments on commit 0a0fd9d

Please sign in to comment.