Skip to content
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
34 changes: 20 additions & 14 deletions src/problem.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,14 @@
#include <stdlib.h>
#include <string.h>

problem *new_problem(expr *objective, expr **constraints, int n_constraints,
bool verbose)
/* Store the objective and constraints in the problem, which holds one
reference on each. */
static void set_objective_and_constraints(problem *prob, expr *objective,
expr **constraints, int n_constraints)
{
#ifdef SP_TRACK_MEMORY
/* Start the high-water mark at the current live count: allocations made
before new_problem (e.g. in left_matmul) stay counted, and their frees
subtract from the live count as usual. */
sp_memory_reset_peak();
#endif
problem *prob = (problem *) sp_calloc(1, sizeof(problem));
if (!prob) return NULL;

/* objective */
prob->objective = objective;
expr_retain(objective);
prob->n_vars = objective->n_vars;

/* constraints array */
prob->total_constraint_size = 0;
prob->n_constraints = n_constraints;
if (n_constraints > 0)
Expand All @@ -56,6 +46,22 @@ problem *new_problem(expr *objective, expr **constraints, int n_constraints,
expr_retain(constraints[i]);
}
}
}

problem *new_problem(expr *objective, expr **constraints, int n_constraints,
bool verbose)
{
#ifdef SP_TRACK_MEMORY
/* Start the high-water mark at the current live count: allocations made
before new_problem (e.g. in left_matmul) stay counted, and their frees
subtract from the live count as usual. */
sp_memory_reset_peak();
#endif
problem *prob = (problem *) sp_calloc(1, sizeof(problem));
if (!prob) return NULL;

prob->n_vars = objective->n_vars;
set_objective_and_constraints(prob, objective, constraints, n_constraints);

/* allocation */
prob->constraint_values =
Expand Down
Loading