aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-07-24 22:11:03 +0530
committersinanmohd <sinan@sinanmohd.com>2024-07-24 22:11:03 +0530
commit2680273a9f3679d4a9c79f203d1b39fc71c833ec (patch)
tree50292a594a07e47b9320e92ff5eb6df6cf77fb2a
parent81f04e0be44572680a3321ffa8ca0d72338eb3c2 (diff)
solver_highs: increment the correct iterator
-rw-r--r--src/evanix.c2
-rw-r--r--src/solver_highs.c24
2 files changed, 16 insertions, 10 deletions
diff --git a/src/evanix.c b/src/evanix.c
index 80a5b25..9f514c4 100644
--- a/src/evanix.c
+++ b/src/evanix.c
@@ -1,7 +1,7 @@
+#include <errno.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
#include "build.h"
#include "evanix.h"
diff --git a/src/solver_highs.c b/src/solver_highs.c
index 722fe27..f68216f 100644
--- a/src/solver_highs.c
+++ b/src/solver_highs.c
@@ -1,4 +1,3 @@
-#include <assert.h>
#include <errno.h>
#include <highs/interfaces/highs_c_api.h>
#include <math.h>
@@ -53,10 +52,6 @@ static int solver_highs_unwrapped(double *solution, struct job_clist *q,
for (size_t i = 0; i < jobid->filled; i++)
col_upper[i] = 1.0;
- integrality = malloc(jobid->filled * sizeof(*integrality));
- for (size_t i = 0; i < jobid->filled; i++)
- integrality[i] = 1;
-
highs = Highs_create();
ret = Highs_setBoolOptionValue(highs, "output_flag", 1);
if (ret != kHighsStatusOk) {
@@ -64,6 +59,7 @@ static int solver_highs_unwrapped(double *solution, struct job_clist *q,
ret = -EPERM;
goto out_free_col_profit;
}
+
ret = Highs_addCols(highs, jobid->filled, col_profit, col_lower,
col_upper, 0, NULL, NULL, NULL);
if (ret != kHighsStatusOk) {
@@ -91,8 +87,8 @@ static int solver_highs_unwrapped(double *solution, struct job_clist *q,
for (size_t i = 0; i < jobid->filled; i++)
constraint_value[i] = 1.0;
- ret = Highs_addRow(highs, 0, resources, jobid->filled + 1,
- constraint_index, constraint_value);
+ ret = Highs_addRow(highs, 0, resources, jobid->filled, constraint_index,
+ constraint_value);
if (ret != kHighsStatusOk) {
print_err("%s", "highs did not return kHighsStatusOk");
ret = -EPERM;
@@ -101,7 +97,7 @@ static int solver_highs_unwrapped(double *solution, struct job_clist *q,
/* set precedance constraints */
CIRCLEQ_FOREACH (j, q, clist) {
- for (size_t i = 0; i < j->deps_filled; j++) {
+ for (size_t i = 0; i < j->deps_filled; i++) {
/* follow the CSR matrix structure */
if (j->id < j->deps[i]->id) {
precedence_index[0] = j->id;
@@ -127,6 +123,15 @@ static int solver_highs_unwrapped(double *solution, struct job_clist *q,
ret = -EPERM;
goto out_free_col_profit;
}
+
+ integrality = malloc(jobid->filled * sizeof(*integrality));
+ if (integrality == NULL) {
+ print_err("%s", strerror(errno));
+ ret = -errno;
+ goto out_free_col_profit;
+ }
+ for (size_t i = 0; i < jobid->filled; i++)
+ integrality[i] = 1;
ret = Highs_changeColsIntegralityByMask(highs, integrality,
integrality);
if (ret != kHighsStatusOk) {
@@ -134,6 +139,7 @@ static int solver_highs_unwrapped(double *solution, struct job_clist *q,
ret = -EPERM;
goto out_free_col_profit;
}
+
ret = Highs_run(highs);
if (ret != kHighsStatusOk) {
print_err("%s", "highs did not return kHighsStatusOk");
@@ -199,7 +205,7 @@ int solver_highs(struct job **job, struct job_clist *q, int32_t resources)
if (ret < 0)
goto out_free_jobid;
- for (size_t i = 0; i < jobid->size; i++) {
+ for (size_t i = 0; i < jobid->filled; i++) {
if (solution[i] == 0.0)
job_stale_set(jobid->jobs[i]);
}