Skip to content

Commit

Permalink
Fixing bugs when no feasible solution found
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickOHara committed Aug 14, 2023
1 parent e9986a7 commit 6e70364
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
11 changes: 8 additions & 3 deletions pctsp/apps/tables_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ def cost_cover_table(
ccdf: pd.DataFrame = pd.read_csv(filename)
ccdf = ccdf.loc[ccdf["cost_function"] != EdgeWeightType.SEMI_MST]
# create new columns
ccdf["gap"] = (ccdf["upper_bound"] - ccdf["lower_bound"]) / ccdf["lower_bound"]
ccdf["optimal"] = ccdf["gap"] == 0
SCIP_STATUS_OPTIMAL = 11 # see https://www.scipopt.org/doc/html/type__stat_8h_source.php
SCIP_STATUS_INFEASIBLE = 12
ccdf["gap"] = ccdf.apply(lambda x: np.nan if x["status"] == SCIP_STATUS_INFEASIBLE else (x["upper_bound"] - x["lower_bound"]) / x["lower_bound"], axis="columns")
ccdf["optimal"] = (ccdf["gap"] == 0) & (ccdf["status"] == SCIP_STATUS_OPTIMAL)

def get_cc_name(cc_disjoint_paths: bool, cc_shortest_paths: bool) -> str:
if cc_disjoint_paths and not cc_shortest_paths:
Expand Down Expand Up @@ -286,14 +288,17 @@ def get_cc_name(cc_disjoint_paths: bool, cc_shortest_paths: bool) -> str:
df = df.drop(
[
"avg_cuts",
"num_feasible_solutions",
"num_cost_cover_disjoint_paths",
"num_cost_cover_shortest_paths",
"nconss_presolve_disjoint_paths",
"nconss_presolve_shortest_paths",
],
axis="columns",
)
if experiment_name == ExperimentName.cc_londonaq_alpha:
df = df.drop("num_optimal_solutions", axis="columns")
elif experiment_name == ExperimentName.cost_cover:
df = df.drop("num_feasible_solutions", axis="columns")
df = df.unstack()
df = df.swaplevel(0, 1, axis="columns").sort_index(axis=1)
df = pretty_dataframe(df)
Expand Down
27 changes: 19 additions & 8 deletions src/algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ std::vector<std::pair<PCTSPvertex, PCTSPvertex>> solvePrizeCollectingTSP(
) {
auto edge_var_map = modelPrizeCollectingTSP(scip, graph, heuristic_edges, cost_map, prize_map, quota, root_vertex, name);
SCIPsolve(scip);
SCIP_SOL* sol = SCIPgetBestSol(scip);
auto solution_edges = getSolutionEdges(scip, graph, sol, edge_var_map);
return getVertexPairVectorFromEdgeSubset(graph, solution_edges);
if (SCIPgetStatus(scip) != SCIP_INFEASIBLE) {
SCIP_SOL* sol = SCIPgetBestSol(scip);
auto solution_edges = getSolutionEdges(scip, graph, sol, edge_var_map);
return getVertexPairVectorFromEdgeSubset(graph, solution_edges);
}
return std::vector<std::pair<PCTSPvertex, PCTSPvertex>>();
}

std::vector<std::pair<PCTSPvertex, PCTSPvertex>> solvePrizeCollectingTSP(
Expand All @@ -55,9 +58,13 @@ std::vector<std::pair<PCTSPvertex, PCTSPvertex>> solvePrizeCollectingTSP(
) {
auto edge_var_map = modelPrizeCollectingTSP(scip, graph, edge_list, heuristic_edges, cost_dict, prize_dict, quota, root_vertex, name);
SCIPsolve(scip);
SCIP_SOL* sol = SCIPgetBestSol(scip);
auto solution_edges = getSolutionEdges(scip, graph, sol, edge_var_map);
return getVertexPairVectorFromEdgeSubset(graph, solution_edges);
if (SCIPgetStatus(scip) != SCIP_INFEASIBLE) {
SCIP_SOL* sol = SCIPgetBestSol(scip);
auto solution_edges = getSolutionEdges(scip, graph, sol, edge_var_map);
return getVertexPairVectorFromEdgeSubset(graph, solution_edges);
}
BOOST_LOG_TRIVIAL(info) << "Solution is not feasible. Returning empty solution vector.";
return std::vector<std::pair<PCTSPvertex, PCTSPvertex>>();
}

SummaryStats getSummaryStatsFromSCIP(SCIP* scip) {
Expand Down Expand Up @@ -198,10 +205,14 @@ std::vector<std::pair<PCTSPvertex, PCTSPvertex>> solvePrizeCollectingTSP(

// solve the model
SCIPsolve(scip);
BOOST_LOG_TRIVIAL(info) << "SCIP solve has finished.";

// get the solution
SCIP_SOL* sol = SCIPgetBestSol(scip);
auto solution_edges = getSolutionEdges(scip, graph, sol, edge_var_map);
std::vector<PCTSPedge> solution_edges = std::vector<PCTSPedge>();
if (SCIPgetNSols(scip) > 0) {
SCIP_SOL* sol = SCIPgetBestSol(scip);
auto solution_edges = getSolutionEdges(scip, graph, sol, edge_var_map);
}

// get the node stats of the solver
// auto node_stats = node_eventhdlr->getNodeStatsVector();
Expand Down

0 comments on commit 6e70364

Please sign in to comment.