From: APTX Date: Thu, 27 Jan 2011 18:44:05 +0000 (+0100) Subject: Add quality measurement to approx algorithms. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=HEAD;p=tal.git Add quality measurement to approx algorithms. --- diff --git a/tal-algorithm/main.cpp b/tal-algorithm/main.cpp index 7a672e3..57250af 100644 --- a/tal-algorithm/main.cpp +++ b/tal-algorithm/main.cpp @@ -325,6 +325,7 @@ int main(int argc, char **argv) Problem *p = 0; bool printSolutions = true; + int optimal = 0; if (argc < 2) goto help; @@ -377,22 +378,29 @@ int main(int argc, char **argv) if (run_dp) { solve_dp(p); + optimal = p->totalValue; if(printSolutions) cout << "dp\tresult\t" << p->totalValue << "\t" << p->totalWeight << endl; } if (run_greedy_HighestValue) { solve_greedy(p, greed_HighestValue); - if(printSolutions) cout << "gv\tresult\t" << p->totalValue << "\t" << p->totalWeight << endl; + if(printSolutions) {cout << "gv\tresult\t" << p->totalValue << "\t" << p->totalWeight; + if(optimal) cout << "\t" << (p->totalValue * 100 / optimal); + cout << endl;} } if (run_greedy_LowestWeight) { solve_greedy(p, greed_LowestWeight); - if(printSolutions) cout << "gw\tresult\t" << p->totalValue << "\t" << p->totalWeight << endl; + if(printSolutions) {cout << "gw\tresult\t" << p->totalValue << "\t" << p->totalWeight; + if(optimal) cout << "\t" << (p->totalValue * 100 / optimal); + cout << endl;} } if (run_greedy_BestRatio) { solve_greedy(p, greed_BestRatio); - if(printSolutions) cout << "gr\tresult\t" << p->totalValue << "\t" << p->totalWeight << endl; + if(printSolutions) {cout << "gr\tresult\t" << p->totalValue << "\t" << p->totalWeight; + if(optimal) cout << "\t" << (p->totalValue * 100 / optimal); + cout << endl;} } printSolutions = false; }