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

model.matrices.c is being coherrsed to int #200

Closed
dannyopts opened this issue Nov 10, 2023 · 1 comment · Fixed by #201
Closed

model.matrices.c is being coherrsed to int #200

dannyopts opened this issue Nov 10, 2023 · 1 comment · Fixed by #201

Comments

@dannyopts
Copy link
Contributor

dannyopts commented Nov 10, 2023

When accessing model.matrices.c the value is coherrsed to int (see failing test below)

This is because when c is created, it has a default value of 0, which is used to create the initial vector.

create_vector(vars, ds.coeffs, fill_value=0, shape=shape)

switching this default to 0.0 fixes the issue.

I will raise a PR to fix this now

def test_matrices_float_c():
    m = Model()

    x = m.add_variables(pd.Series([0, 0]), 1, name="x")
    m.add_objective(x * 1.5)

    c = m.matrices.c
    assert np.all(c == np.array([1.5, 1.5])) 

Fails with

  assert np.all(c == np.array([1.5, 1.5]))

E assert False
E + where False = <function all at 0x1044e5b30>(array([1, 1]) == array([1.5, 1.5])

@dannyopts
Copy link
Contributor Author

dannyopts commented Nov 10, 2023

This causes a bug when using the direct api that cost coeffs are rounded to ints

>>> m = Model()
>>> x = m.add_variables(name="x")
>>> m.add_objective(0.1 * x)
>>> m.solve("highs", "direct")
>>> m.objective.value
0.0
>>> m.solve("highs", "lp")
>>> m.objective.value
nan

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 a pull request may close this issue.

1 participant