Skip to content

Commit

Permalink
Update for runing benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlyqing00 committed Dec 17, 2018
1 parent 3479bc3 commit a9cffc7
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 86 deletions.
31 changes: 31 additions & 0 deletions benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

test_n=4
nums=(20 30 40 50)
samples=(30 50 70 100)
metrics=(0 2)
compositions=(0 1)

if [ $# == 0 ]; then
echo "Enter a test case name."
echo "End."
exit
fi

echo "Test case: "$var
for i in $(seq 0 ${test_n}); do
./bin/release/generator -t $1 -n ${nums[i]}
echo " "

for metric in ${metrics[@]}; do
for comp in ${compositions[@]}; do
./bin/release/solver \
-t $1 \
-n ${nums[i]} \
-m ${metric} \
-c ${comp} \
-s ${samples[i]}
echo " "
done
done
done
1 change: 1 addition & 0 deletions include/solve_puzzle.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <unistd.h>
#include <string>
#include <fstream>
#include <ctime>
#include <opencv2/opencv.hpp>

#include <stripes_solver.h>
Expand Down
9 changes: 6 additions & 3 deletions include/stripes_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ class StripesSolver {

enum Metric {
PIXEL,
CHAR,
WORD,
COMP_EVA
};

enum Composition {
GREEDY,
GREEDY_PROBABILITY
GCOM,
};

const string puzzle_folder;
Expand All @@ -45,6 +46,7 @@ class StripesSolver {
vector<int> composition_order;
cv::Mat composition_img;
cv::Mat composition_img_seams;
double composition_score;

// Path
PathManager path_manager;
Expand All @@ -65,6 +67,7 @@ class StripesSolver {
Composition composition_mode;

vector<StripePair> stripe_pairs;
vector<StripePair> stripe_pairs_pixel;

// Tesseract
const string tesseract_model_path {"data/tesseract_model/"};
Expand All @@ -86,11 +89,11 @@ class StripesSolver {
int sols_n = 10;
vector< vector<double> > pixel_graph;

double m_metric_word(const cv::Mat & piece0, const cv::Mat & piece1);
double m_metric_char(const cv::Mat & piece0, const cv::Mat & piece1);
double m_metric_comp_eva(const cv::Mat & piece0, const cv::Mat & piece1);

vector< vector<int> > reassemble_greedy(bool probability_flag=false);
void reassemble_greedy_probability();
void reassemble_GCOM();

cv::Mat word_detection( const cv::Mat & img,
const vector<int> & sol,
Expand Down
2 changes: 1 addition & 1 deletion src/solver/path_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ vector<StripePair> PathManager::build_stripe_pairs() {
for (int i = 0; i < nodes_n; i++) {
for (const auto & edge: path_graph[i]) {

if (edge.second < 3) continue;
// if (edge.second < 3) continue;
stripe_pairs.push_back(StripePair(
i,
edge.first,
Expand Down
9 changes: 8 additions & 1 deletion src/solver/solve_puzzle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ void solve_stripes( const string & stripes_folder,
stripes_solver.reassemble(metric_mode, composition_mode);
stripes_solver.save_result(case_name);

#ifdef DEBUG
for (int idx: stripes_solver.composition_order) {
cout << idx << endl;
}

cv::imshow("Composition Image", stripes_solver.composition_img);
cv::imshow("Composition Image Seams", stripes_solver.composition_img_seams);
cv::waitKey();

#endif
}

void solve_squares (const string & squares_folder,
Expand Down Expand Up @@ -112,6 +113,8 @@ int main(int argc, char ** argv) {
cout << "Samples times: \t" << samples_n << endl;
cout << "Composition mode: \t" << (composition_mode == StripesSolver::Composition::GREEDY ? "Greedy" : "Greedy Probability") << endl;

clock_t start_time = clock();

// Import stripes
if (puzzle_type == PuzzleType::STRIPES) {

Expand All @@ -125,5 +128,9 @@ int main(int argc, char ** argv) {

}

clock_t end_time = clock();

cout << "Time used: " << double(end_time - start_time) / CLOCKS_PER_SEC << " s" << endl << endl;

return 0;
}
Loading

0 comments on commit a9cffc7

Please sign in to comment.