uestla / Simplex-Calculator

PHP tool for linear programming problems solving
http://simplex.wz.cz/
39 stars 19 forks source link

Inaccessible Basis #18

Closed Domi04151309 closed 1 year ago

Domi04151309 commented 1 year ago

It would be nice to allow access to the basis variable in the Table class by implementing a getter.

Domi04151309 commented 1 year ago

I propose to add the following function to Table.php

/** @return array */
function getBasis()
{
  return array_map(fn ($value) => $value->getVar(), $this->rows);
}
uestla commented 1 year ago

@Domi04151309 Thanks, the basis was already present in $basis variable, so I just added a getter.

Domi04151309 commented 1 year ago

I suggested the above function because the basis variable does not get reset after each iteration. See the below image for the difference: image It uses the example from the README.

uestla commented 1 year ago

@Domi04151309 You're absolutely right. The basis was not being reset on each solution step. I fixed it and also added a test that uses the example task (as you mentioned). Could you please test it now?


On a side note: This is an issue that is connected to my poor design decision that I've made at the very beginning of this project and has to do with mutable objects. I'm currently working on version 2 of this library that deals with all these bottlenecks and will hopefully be much easier to use and hopefully bring big performance boost in the calculation. If everything goes well, also basis cycling detection will be implemented :-)

Stay tuned!

Domi04151309 commented 1 year ago

Thanks for the fix! Works as intended now.