Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opti: No early stop until 1st solution is found #84

Merged
merged 1 commit into from
Jul 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/opti-lib/src/OptimizerEnProfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using namespace EnjoLib;

const int OptimizerEnProfit::HOURS_IN_DAY = 24;
const int OptimizerEnProfit::MAX_NUM_COMBINATIONS = 1e7;
const double OptimizerEnProfit::MAX_FAILED_COMBINATIONS = 0.6;
const double OptimizerEnProfit::MAX_FAILED_COMBINATIONS = 0.40;
const double OptimizerEnProfit::MIN_POS_2_NEG_CHANGE_RATIO = 0.01;

OptimizerEnProfit::OptimizerEnProfit(const OptiEnProfitDataModel & dataModel)
Expand Down Expand Up @@ -96,6 +96,7 @@ void OptimizerEnProfit::RandomSearch()
}
Matrix binarBest = binaryMat;

bool foundFirstSolution = false;
const bool useHash = IsUseHash();
const int maxCombisFailed = MAX_NUM_COMBINATIONS * MAX_FAILED_COMBINATIONS;
short bit = 1;
Expand Down Expand Up @@ -170,6 +171,7 @@ void OptimizerEnProfit::RandomSearch()
binarBest = binaryMat;
m_uniqueSolutionsPrev = m_uniqueSolutions;
m_uniqueSolutions = usedCombinations.size();
foundFirstSolution = true;
}
else
{
Expand All @@ -181,7 +183,7 @@ void OptimizerEnProfit::RandomSearch()
const bool changeLargeEnough = m_relPos2Neg == 0 || m_relPos2Neg > MIN_POS_2_NEG_CHANGE_RATIO;
const bool exceededNumFailed = m_numFailed >= maxCombisFailed;
//if (exceededNumFailed && not changeLargeEnough)
if (exceededNumFailed)
if (exceededNumFailed && foundFirstSolution)
{
LOGL << "Early stop after " << m_numFailed << " last failed attempts "
// << and last change of " << m_relPos2Neg << " < " << MIN_POS_2_NEG_CHANGE_RATIO << Nl
Expand Down