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

Speed up MixedIntegerLinearProgram #7740

Closed
nathanncohen mannequin opened this issue Dec 19, 2009 · 14 comments
Closed

Speed up MixedIntegerLinearProgram #7740

nathanncohen mannequin opened this issue Dec 19, 2009 · 14 comments

Comments

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Dec 19, 2009

From Robert Miller :

sage: from sage.graphs.graph_coloring import vertex_coloring
sage: g = graphs.CirculantGraph(120, [2,3,5,7])
sage: vertex_coloring(g)

It takes longer to set up the constraint than to solve the problem, on my laptop.

CC: @rlmill

Component: numerical

Author: Nathann Cohen

Reviewer: Robert Miller

Merged: sage-4.3.1.alpha2

Issue created by migration from https://trac.sagemath.org/ticket/7740

@nathanncohen nathanncohen mannequin added this to the sage-4.3.1 milestone Dec 19, 2009
@nathanncohen nathanncohen mannequin changed the title Spped up MixedIntegerLinearProgram Speed up MixedIntegerLinearProgram Dec 19, 2009
@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Dec 20, 2009

comment:2

Well, this time is spent as expected on the add_constraint function, which may spend time over considerations coming from symbolic computations, though I did not achieve to know where... When I am profiling your example I see :


25448/21366    0.529    0.000    0.695    0.000 complex_interval_field.py:257(__call__)
     8642    0.427    0.000    1.136    0.000 complex_interval_field.py:330(random_element)
     8642    0.106    0.000    0.117    0.000 complex_interval_field.py:325(gen)

These functions are the ones responsible for the time spent defining the LP, but I could not find which line of add_constraint is calling them... If you have any idea, please tell me and I'll give it a look :-)

@nathanncohen nathanncohen mannequin added the s: needs info label Dec 20, 2009
@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Dec 26, 2009

comment:3

This patch adds to the file numerical.mip a class LinearFunction which avoid using the much more general symbolic expressions from Sage ( as we only need to define linear functions ).

Before :

sage: from sage.graphs.graph_coloring import vertex_coloring
sage: g = graphs.CirculantGraph(120, [2,3,5,7])
sage: timeit("vertex_coloring(g)")
5 loops, best of 3: 3.94 s per loop

After :

sage: from sage.graphs.graph_coloring import vertex_coloring
sage: g = graphs.CirculantGraph(120, [2,3,5,7])
sage: timeit("vertex_coloring(g)")
5 loops, best of 3: 2.18 s per loop

The next way to speed up this class would be, methinks, to cythonize it. I tried it this time but got stuck by the fact that the solving functions ( solveCoin, solveGlpk ) are not directly included in Sage and installed by the packages... The best way would really be to move these sources into Sage. It would also solve solve the problem of having to update both packages and numerical.mip t the same time .. :-/

Nathann

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Dec 28, 2009

comment:5

Before :

sage: g = graphs.WorldMap()
sage: %timeit g.edge_connectivity()
10 loops, best of 3: 1.29 s per loop

After :

sage: g = graphs.WorldMap()
sage: %timeit g.edge_connectivity()
10 loops, best of 3: 231 ms per loop

But as mentionned earlier, we will have to find other ways to improve this class ! :-)

Nathann

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jan 6, 2010

comment:6

Looks good to me! Aside from this typo:
"An elementary algebra algebra"

@rlmill rlmill mannequin added s: needs work and removed s: needs review labels Jan 6, 2010
@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 9, 2010

Attachment: trac_7740.patch.gz

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 9, 2010

comment:7

Here it is ! :-)

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jan 13, 2010

Author: Nathann Cohen

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jan 13, 2010

Merged: 4.3.1.alpha2

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jan 13, 2010

comment:8

positive review

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jan 13, 2010

Reviewer: Robert Miller

@rlmill rlmill mannequin removed the s: needs review label Jan 13, 2010
@rlmill rlmill mannequin closed this as completed Jan 13, 2010
@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 13, 2010

comment:9

Thank you again !!! I was longing for this one :-)

Nathann

@sagetrac-mvngu
Copy link
Mannequin

sagetrac-mvngu mannequin commented Jan 13, 2010

Changed merged from 4.3.1.alpha2 to sage-4.3.1.alpha2

@nthiery
Copy link
Contributor

nthiery commented Jan 14, 2010

comment:11

Hi Nathan,

Sorry to pop up late into the discussion. What was the rationale for not using CombinatorialFreeModule(whatever_ring, ZZ)?

For the record, I very much hope that FreeModule(ring, infinity, sparse = True) will be available sometime soon. That will be a faster alternative.

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented Jan 14, 2010

comment:12

Hello !

At first I used InfinitePolynomialRing, then plain "vars", then I just wondered why it was still very slow and just wondered what it would give if I were to write the symbolics myself to understand... As it was easy enough, I wrote something to try it on my computer, and ended up writing a patch to send the code.

This way, it stores the informations in a format that is optimal for what I need ( no powers --only linear functions--, sparse from the beginning, ... ). Since, I have also noticed that having my own symbolics would let me define expressions like double inequalities :

0 < a + b < 9

Which I had been missing for a long time.. :-)
The main problem I have is that in many cases, the symbolics take most of the time spent on the computation of a matching (or other LP problems), which is quite disturbing ;-)

Nathann

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant