From ef8272ae34c905f61cb8fe1fcce9d0c1238c0c37 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Fri, 30 Aug 2024 21:54:35 +0530 Subject: solver_highs: drop zero values from constraint matrix --- src/jobs.c | 3 +++ src/solver_highs.c | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/jobs.c b/src/jobs.c index ee9c77f..f9e74db 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -224,6 +224,9 @@ int job_cost(struct job *job) int ret; char *pname; + if (job->insubstituters) + return 0; + if (!evanix_opts.max_time) return 1; diff --git a/src/solver_highs.c b/src/solver_highs.c index e3b6a1f..b641e54 100644 --- a/src/solver_highs.c +++ b/src/solver_highs.c @@ -14,6 +14,7 @@ static int solver_highs_unwrapped(double *solution, struct job_clist *q, { HighsInt precedence_index[2]; double precedence_value[2]; + int num_non_zero; struct job *j; int ret; @@ -80,24 +81,27 @@ static int solver_highs_unwrapped(double *solution, struct job_clist *q, ret = -errno; goto out_free_col_profit; } - for (size_t i = 0; i < jobid->filled; i++) - constraint_index[i] = i; - constraint_value = malloc(jobid->filled * sizeof(*constraint_value)); if (constraint_value == NULL) { print_err("%s", strerror(errno)); ret = -errno; goto out_free_col_profit; } + + num_non_zero = 0; for (size_t i = 0; i < jobid->filled; i++) { ret = job_cost(jobid->jobs[i]); if (ret < 0) return ret; + else if (ret == 0) + continue; - constraint_value[i] = ret; + constraint_value[num_non_zero] = ret; + constraint_index[num_non_zero] = i; + num_non_zero++; } - ret = Highs_addRow(highs, 0, resources, jobid->filled, constraint_index, + ret = Highs_addRow(highs, 0, resources, num_non_zero, constraint_index, constraint_value); if (ret != kHighsStatusOk) { print_err("%s", "highs did not return kHighsStatusOk"); -- cgit v1.2.3