Skip to content

Commit

Permalink
Improve debug files naming
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaslundell committed Sep 16, 2023
1 parent bf1c961 commit d129ac7
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 130 deletions.
2 changes: 2 additions & 0 deletions src/DualSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ void DualSolver::addIntegerCut(IntegerCut integerCut)
{
if(env->reformulatedProblem->properties.numberOfIntegerVariables > 0
|| env->reformulatedProblem->properties.numberOfSemiintegerVariables > 0)
{
integerCut.areAllVariablesBinary = false;
}
else
{
integerCut.areAllVariablesBinary = true;
Expand Down
43 changes: 19 additions & 24 deletions src/MIPSolver/MIPSolverCbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,15 +793,14 @@ E_ProblemSolutionStatus MIPSolverCbc::solveProblem()
{
if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lp";
ss << env->results->getCurrentIteration()->iterationNumber - 1;
ss << "unbounded.lp";

auto filename = fmt::format("{}/dualiter{}_unbounded.lp",
env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->results->getCurrentIteration()->iterationNumber - 1);

try
{
osiInterface->writeLp(ss.str().c_str(), "", 1e-7, 10, 10, 0.0, true);
osiInterface->writeLp(filename.c_str(), "", 1e-7, 10, 10, 0.0, true);
}
catch(std::exception& e)
{
Expand Down Expand Up @@ -890,12 +889,11 @@ bool MIPSolverCbc::repairInfeasibility()
constraints[i] = osiInterface->getRowName(repairConstraints[i]);
}

std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lp";
ss << env->results->getCurrentIteration()->iterationNumber - 1;
ss << "repairedweights.txt";
Utilities::saveVariablePointVectorToFile(relaxParameters, constraints, ss.str());
auto filename = fmt::format("{}/dualiter{}_infeasrelaxweights.txt",
env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->results->getCurrentIteration()->iterationNumber - 1);

Utilities::saveVariablePointVectorToFile(relaxParameters, constraints, filename);
}

for(int i = 0; i < numConstraintsToRepair; i++)
Expand All @@ -922,15 +920,13 @@ bool MIPSolverCbc::repairInfeasibility()

if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lp";
ss << env->results->getCurrentIteration()->iterationNumber - 1;
ss << "infeasrelax.lp";
auto filename = fmt::format("{}/dualiter{}_infeasrelax.lp",
env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->results->getCurrentIteration()->iterationNumber - 1);

try
{
repairedInterface->writeLp(ss.str().c_str(), "", 1e-7, 10, 10, 0.0, true);
repairedInterface->writeLp(filename.c_str(), "", 1e-7, 10, 10, 0.0, true);
}
catch(std::exception& e)
{
Expand Down Expand Up @@ -1130,12 +1126,11 @@ bool MIPSolverCbc::repairInfeasibility()

if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lp";
ss << env->results->getCurrentIteration()->iterationNumber - 1;
ss << "repaired.lp";
writeProblemToFile(ss.str());
auto filename = fmt::format("{}/dualiter{}_infeasrelax.lp",
env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->results->getCurrentIteration()->iterationNumber - 1);

writeProblemToFile(filename);
}

delete repairedInterface;
Expand Down
26 changes: 13 additions & 13 deletions src/MIPSolver/MIPSolverCplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,12 +914,11 @@ bool MIPSolverCplex::repairInfeasibility()
constraints[i] = expression.str();
}

std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lp";
ss << env->results->getCurrentIteration()->iterationNumber - 1;
ss << "repairedweights.txt";
Utilities::saveVariablePointVectorToFile(weights, constraints, ss.str());
auto filename = fmt::format("{}/dualiter{}_infeasrelaxweights.txt",
env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->results->getCurrentIteration()->iterationNumber - 1);

Utilities::saveVariablePointVectorToFile(weights, constraints, filename);
}

if(cplexInstance.feasOpt(cplexConstrs, relax))
Expand Down Expand Up @@ -958,12 +957,11 @@ bool MIPSolverCplex::repairInfeasibility()

if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lp";
ss << env->results->getCurrentIteration()->iterationNumber - 1;
ss << "repaired.lp";
writeProblemToFile(ss.str());
auto filename = fmt::format("{}/dualiter{}_infeasrelax.lp",
env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->results->getCurrentIteration()->iterationNumber - 1);

writeProblemToFile(filename);
}

if(numRepairs == 0)
Expand Down Expand Up @@ -1141,7 +1139,9 @@ void MIPSolverCplex::setTimeLimit(double seconds)
{
try
{
if(seconds > 1e+75) { }
if(seconds > 1e+75)
{
}
else if(seconds > 0)
{
cplexInstance.setParam(IloCplex::Param::TimeLimit, seconds);
Expand Down
32 changes: 14 additions & 18 deletions src/MIPSolver/MIPSolverGurobi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,12 +953,11 @@ bool MIPSolverGurobi::repairInfeasibility()
constraints[i] = repairConstraints[i].get(GRB_StringAttr_ConstrName);
}

std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lp";
ss << env->results->getCurrentIteration()->iterationNumber - 1;
ss << "repairedweights.txt";
Utilities::saveVariablePointVectorToFile(relaxParameters, constraints, ss.str());
auto filename = fmt::format("{}/dualiter{}_infeasrelaxweights.txt",
env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->results->getCurrentIteration()->iterationNumber - 1);

Utilities::saveVariablePointVectorToFile(relaxParameters, constraints, filename);
}

// Gurobi modifies the value when running feasModel.optimize()
Expand All @@ -977,15 +976,13 @@ bool MIPSolverGurobi::repairInfeasibility()
// Saves the relaxation model to file
if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lp";
ss << env->results->getCurrentIteration()->iterationNumber - 1;
ss << "infeasrelax.lp";
auto filename = fmt::format("{}/dualiter{}_infeasrelax.lp",
env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->results->getCurrentIteration()->iterationNumber - 1);

try
{
feasModel.write(ss.str());
feasModel.write(filename);
}
catch(GRBException& e)
{
Expand Down Expand Up @@ -1025,12 +1022,11 @@ bool MIPSolverGurobi::repairInfeasibility()

if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lp";
ss << env->results->getCurrentIteration()->iterationNumber - 1;
ss << "repaired.lp";
writeProblemToFile(ss.str());
auto filename = fmt::format("{}/dualiter{}_infeasrelax.lp",
env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->results->getCurrentIteration()->iterationNumber - 1);

writeProblemToFile(filename);
}

if(numRepairs == 0)
Expand Down
30 changes: 12 additions & 18 deletions src/NLPSolver/NLPSolverCuttingPlaneMinimax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,10 @@ E_NLPSolutionStatus NLPSolverCuttingPlaneMinimax::solveProblemInstance()
// Saves the LP problem to file if in debug mode
if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lpminimax";
ss << i;
ss << ".lp";
LPSolver->writeProblemToFile(ss.str());
auto filename
= fmt::format("{}/minimax{}.lp", env->settings->getSetting<std::string>("Debug.Path", "Output"), i);

LPSolver->writeProblemToFile(filename);
}

// Solves the problem and obtains the solution
Expand Down Expand Up @@ -193,12 +191,10 @@ E_NLPSolutionStatus NLPSolverCuttingPlaneMinimax::solveProblemInstance()
// Saves the LP solution to file if in debug mode
if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lpminimaxsolpt";
ss << i;
ss << ".txt";
Utilities::saveVariablePointVectorToFile(LPVarSol, variableNames, ss.str());
auto filename = fmt::format(
"{}/minimax{}_solpt.txt", env->settings->getSetting<std::string>("Debug.Path", "Output"), i);

Utilities::saveVariablePointVectorToFile(LPVarSol, variableNames, filename);
}

if(std::isnan(LPObjVar))
Expand Down Expand Up @@ -238,12 +234,10 @@ E_NLPSolutionStatus NLPSolverCuttingPlaneMinimax::solveProblemInstance()
// Saves the LP solution to file if in debug mode
if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::stringstream ss;
ss << env->settings->getSetting<std::string>("Debug.Path", "Output");
ss << "/lpminimaxlinesearchsolpt";
ss << i;
ss << ".txt";
Utilities::saveVariablePointVectorToFile(currSol, variableNames, ss.str());
auto filename = fmt::format(
"{}/minimax{}_lsearchsolpt.txt", env->settings->getSetting<std::string>("Debug.Path", "Output"), i);

Utilities::saveVariablePointVectorToFile(currSol, variableNames, filename);
}
}

Expand Down
20 changes: 8 additions & 12 deletions src/Results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,14 @@ void Results::addPrimalSolution(PrimalSolution solution)
if(env->problem->objectiveFunction->properties.isMinimize)
{
std::sort(this->primalSolutions.begin(), this->primalSolutions.end(),
[](const PrimalSolution& firstSolution, const PrimalSolution& secondSolution) {
return (firstSolution.objValue < secondSolution.objValue);
});
[](const PrimalSolution& firstSolution, const PrimalSolution& secondSolution)
{ return (firstSolution.objValue < secondSolution.objValue); });
}
else
{
std::sort(this->primalSolutions.begin(), this->primalSolutions.end(),
[](const PrimalSolution& firstSolution, const PrimalSolution& secondSolution) {
return (firstSolution.objValue > secondSolution.objValue);
});
[](const PrimalSolution& firstSolution, const PrimalSolution& secondSolution)
{ return (firstSolution.objValue > secondSolution.objValue); });
}

env->solutionStatistics.numberOfFoundPrimalSolutions++;
Expand Down Expand Up @@ -159,13 +157,11 @@ void Results::addPrimalSolution(PrimalSolution solution)
// Write the new primal point to a file
if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::stringstream fileName;
fileName << env->settings->getSetting<std::string>("Debug.Path", "Output");
fileName << "/primalpoint";
fileName << env->solutionStatistics.numberOfFoundPrimalSolutions;
fileName << ".txt";
auto filename
= fmt::format("{}/primal_solpt{}.txt", env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->solutionStatistics.numberOfFoundPrimalSolutions);

savePrimalSolutionToFile(solution, env->problem->allVariables, fileName.str());
savePrimalSolutionToFile(solution, env->problem->allVariables, filename);
}

// TODO: Add primal objective cut
Expand Down
1 change: 0 additions & 1 deletion src/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,6 @@ void Solver::setConvexityBasedSettings()
env->settings->updateSetting("FixedInteger.CallStrategy", "Primal", 0);
env->settings->updateSetting("FixedInteger.CreateInfeasibilityCut", "Primal", false);
env->settings->updateSetting("FixedInteger.Source", "Primal", 0);
env->settings->updateSetting("FixedInteger.Warmstart", "Primal", true);

env->settings->updateSetting("FixedInteger.OnlyUniqueIntegerCombinations", "Primal", false);

Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/TaskCreateDualProblem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TaskCreateDualProblem::TaskCreateDualProblem(EnvironmentPtr envPtr) : TaskBase(e
if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
env->dualSolver->MIPSolver->writeProblemToFile(
env->settings->getSetting<std::string>("Debug.Path", "Output") + "/lp0.lp");
env->settings->getSetting<std::string>("Debug.Path", "Output") + "/dualiter0_problem.lp");
}

env->output->outputDebug(" Dual problem created");
Expand Down
6 changes: 3 additions & 3 deletions src/Tasks/TaskSelectPrimalCandidatesFromNLP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ bool TaskSelectPrimalCandidatesFromNLP::solveFixedNLP()

if(env->settings->getSetting<bool>("Debug.Enable", "Output"))
{
std::string filename = env->settings->getSetting<std::string>("Debug.Path", "Output")
+ "/primalnlp_warmstart" + std::to_string(currIter->iterationNumber) + "_" + std::to_string(counter)
+ ".txt";
auto filename = fmt::format("{}/primalnlp{}_warmstart_{}.txt",
env->settings->getSetting<std::string>("Debug.Path", "Output"),
env->results->getCurrentIteration()->iterationNumber - 1, counter);

Utilities::saveVariablePointVectorToFile(startingPointValues, variableNames, filename);
}
Expand Down

0 comments on commit d129ac7

Please sign in to comment.