From e0ff8dcba440e695c9a57eaba88b41150ecc5fc0 Mon Sep 17 00:00:00 2001 From: APTX Date: Thu, 27 Jan 2011 19:44:05 +0100 Subject: [PATCH] Add quality measurement to approx algorithms. --- tal-algorithm/main.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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; } -- 2.52.0