Skip to content

Commit

Permalink
solver_highs: drop zero values from constraint matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanmohd committed Aug 30, 2024
1 parent 404b98c commit ef8272a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 9 additions & 5 deletions src/solver_highs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit ef8272a

Please sign in to comment.