Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1679 and 1681 #1753

Merged
merged 13 commits into from May 15, 2024
Merged

Fix 1679 and 1681 #1753

merged 13 commits into from May 15, 2024

Conversation

jajhall
Copy link
Sponsor Member

@jajhall jajhall commented May 7, 2024

Renamed

  • addVar to addVariable to prevent shadowing of highspy binding to Highs::addVar
  • Change the name of removeVar to deleteVariable for consistency with Highs::deleteCol
  • Change the name of getVars to getVariables

Added a call of self.update() to addVariable, rather than deferring it to addConstr, to allow column data to be changed, and rows to be added, using highspy bindings to methods in the Highs class. These will assume that all variables that have been defined are in the incumbent model.

Unfortunately - see experiments with examples/distillation.py - this gets the column names wrong. It would appear as if the names stack isn't flushed when self.update() is called. Any thoughts @galabovaa ?

@jajhall jajhall changed the base branch from master to latest May 7, 2024 16:20
@jajhall
Copy link
Sponsor Member Author

jajhall commented May 7, 2024

This will close #1679 and #1681

@jajhall jajhall requested a review from galabovaa May 7, 2024 16:44
@galabovaa galabovaa self-assigned this May 10, 2024
@galabovaa
Copy link
Contributor

galabovaa commented May 12, 2024

OK it does seem that names are not cleared, this seems to be by design because the idea I think was to call update() once all the modelling is done, just before run.

I tried to clear them naively at the end of update() in branch fixx, but that breaks one test:

TestHighsPy::test_deleteVariable FAILED
https://github.com/ERGO-Code/HiGHS/actions/runs/9051630828/job/24868361542

Here is the failing test code:
`
def test_deleteVariable(self):
h = highspy.Highs()
x = [h.addVariable(), h.addVariable()]

    h.update()
    self.assertEqual(h.numVars, 2)

    h.deleteVariable(x[0])
    self.assertEqual(h.numVars, 1)

`

Natually, once I have cleared the list, the modelling language can not find the variable to delete.

I'll investigate further

@jajhall
Copy link
Sponsor Member Author

jajhall commented May 12, 2024

'update()' is called when each constraint is added - otherwise addRow() returns kHighsError.

It seems as if just the names fail - possibly something Luke didn't test.

@galabovaa
Copy link
Contributor

galabovaa commented May 13, 2024

I added a list of names to the batch and now call that with names: see the latest commit.

I thought it would be easier than trying to keep track of batch indices in vars_. Now the batch names are cleared at the end of update() and the column names should look allright

** edit something is not right again because there is a test_var_name failing, will look further

@@ -106,7 +106,9 @@ def update(self):
current_batch_size = len(self._batch.obj)
print("\nDEBUG update(self): On entry - current_batch_size = ", current_batch_size)
if current_batch_size > 0:
names = [self._vars[i].name for i in range(current_batch_size)]
# names = [self._vars[i].name for i in range(current_batch_size)]
names = [self._batch.name[i] for i in range(current_batch_size)]
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this fixes it. It's actually nothing to do with adding update() to addVariables, since this would be wrong once update() has been called for the first non-empty batch.

@jajhall
Copy link
Sponsor Member Author

jajhall commented May 13, 2024

something is not right again because there is a test_var_name failing, will look further

We now can't change name thus

# change name before adding to the model
    x.name = 'y'
    self.assertEqual(x.name, 'y')

    # add to the model
    h.update()

TBH, I can't see a value in allowing this to be possible, so we can delete the test

@jajhall jajhall marked this pull request as ready for review May 15, 2024 18:07
@jajhall jajhall merged commit 990d8b8 into latest May 15, 2024
202 checks passed
@jajhall jajhall deleted the fix-1679-1681 branch May 15, 2024 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants