Problem *p = 0;
bool printSolutions = true;
+ int optimal = 0;
if (argc < 2)
goto help;
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;
}