]> Some of my projects - tal.git/commitdiff
Add quality measurement to approx algorithms. master
authorAPTX <marek321@gmail.com>
Thu, 27 Jan 2011 18:44:05 +0000 (19:44 +0100)
committerAPTX <marek321@gmail.com>
Thu, 27 Jan 2011 18:44:05 +0000 (19:44 +0100)
tal-algorithm/main.cpp

index 7a672e31213443916c589cba96c11b2e3330a286..57250af946af009d27def1a6050adbb4f8cfe5e2 100644 (file)
@@ -325,6 +325,7 @@ int main(int argc, char **argv)
 
        Problem *p = 0;
        bool printSolutions = true;
 
        Problem *p = 0;
        bool printSolutions = true;
+       int optimal = 0;
 
        if (argc < 2)
                goto help;
 
        if (argc < 2)
                goto help;
@@ -377,22 +378,29 @@ int main(int argc, char **argv)
                if (run_dp)
                {
                        solve_dp(p);
                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 << "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 (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 (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;
        }
                }
                printSolutions = false;
        }