1

I created a basic LP model, input the objective function into an array by hand and the model worked fine:

    $ret = lpsolve('set_obj_fn', $lp, array(1, 3, 7, 2));

I moved the array out and referenced it with a variable in the lp_solve function and still everything is fine:

    $objectiveFunction = array(1, 3, 7, 2);
    $ret = lpsolve('set_obj_fn', $lp, $objectiveFunction);

Now, I want to expand on the model by pulling the values for my objective function from a MySQL database. I queried the database for the results and, using a loop, pushed those values into an array.

    $newObjective = array();
    for($i=0; $i&l t;count($sqlResults); $i++) {
         array_push($newObjective, $sqlResults[$i][0]);
    }
    $ret = lpsolve('set_obj_fn', $lp, $newObjective);

This creates a n array that appears to match my original ($objectiveFunction) perfectly. However, when I run the LP model using the array created from the loop, lp_solve returns an error for an 'invalid vector' on the same line where I input my array. I can't figure out why one array would work and another would not.

1 Answers1

0

It looks like lpsolve is expecting an array of floating point numbers.

Changing:

array_push($newObjective, $sqlResults[$i][0]);

To:

array_push($newObjective, (float) $sqlResults[$i][0]);

seems to fix the issue