Fix the O(N^2) bug of passColName and passRowName #1780
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a performance issue when
Highs_addCol
andHighs_passColName
are called in sequence to add new variables.After
Highs_addCol
is called, there isn
columns and thecols_hash_
also hasn
elements because ofHiGHS/src/lp_data/HighsInterface.cpp
Line 201 in 13363c9
HiGHS/src/lp_data/HighsLp.cpp
Line 315 in 13363c9
cols_hash_
will be rebuilt if it is empty.Then, if
Highs_passColName
is called to set the name of columnn
,cols_hash_
is cleared.Now when$O(N^2)$ .
Highs_addCol
andHighs_passColName
are called in sequence to addN
columns,cols_hash_
has to be rebuilt forN
times with length1,2,...,N
, which makes the complexityIn fact, when we call
Highs_passColName
,cols_hash_
can update one element instead of clearing all contents.The bug is discovered in coin-or/python-mip#372 .