Re: [sage-support] Re: Linear Programming - loading LP or MPS file?

2015-09-01 Thread Stephen Hartke
> On Tuesday, 1 September 2015 07:00:39 UTC-7, Craig E Larson wrote:
>> I see that there are methods for saving a LP as and LP or MPS file in
>> Sage. Is it possible to *load* an LP from one of these file types? The
>> online help that I've found doesn't mention this or give examples of how to
>> do it.

On Tue, Sep 1, 2015 at 10:49 AM, Dima Pasechnik  wrote:
> Not that I know. Write one, it will be a valuable addition to Sage...
> (There should be Python code out there on the next that can be adapted, 
> surely...)

Most (all?) of the LP/IP libraries have functions for reading in LP
and MPS files, so it might be simpler to make Python wrappers around
that function in each of the backends.

Best wishes,
Stephen

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Re: add_constraint becomes slow in presence of many constraints

2014-04-29 Thread Stephen Hartke
Adding row constraints one at a time is slow because of the internal data
structures that simplex solvers use.  In large LPs/IPs, the constraint
matrix is almost always sparse, and so allocating an entire dense matrix
doesn't make sense.  Instead, a packed sparse matrix is used.  Because of
the way the simplex algorithm works, quick access is needed to /columns/ of
the constraint matrix, so the sparse matrix format used is ordered by
columns.  When adding a row to such a matrix, the entire matrix needs to be
reordered.  As the matrix gets large, this reordering becomes slower.

One solution is to just give the entire matrix to the solver all at once.
 In GLPK, this matrix does not have to be column ordered, but it is
reordered before solving (see the glp_sort_matrix command; this doesn't
have to be called explicitly by the user but does get performed).  In
CPLEX, the matrix does have to be column ordered, which is somewhat
annoying to do (see CPXcopylp).  Gurobi seems to use a similar matrix
format (Compressed Sparse Column (CSC) format according to their
documentation).  For COIN, a packed sparse matrix is used.  The
documentation doesn't seem to explicitly state that it's column ordered,
but I assume it must be.

The up shot of all this is that it's worth thinking about what a nice Sage
interface for large LP/IPs would look like.  I think allocating a large
dense matrix doesn't make sense because of the sizes involved.  As Peter
pointed out, it's more natural to specify LP/IPs by rows than by columns,
but then a re-ordering must occur at some point.

Best wishes,
Stephen



On Mon, Apr 28, 2014 at 7:49 AM, Nathann Cohen nathann.co...@gmail.comwrote:

 Helloo !!!


 I think this is right. Allocating  copying such a huge matrix repeatedly
 would be terrible. Perhaps we should introduce an API function to
 add_constraints, which takes a list of lists, or a matrix? If a solver
 doesn't support such a thing, we could fall back on the brute force method.


 I am almost sure that all solvers support that. Some allocate new
 constraints function that would just be called befre creating the actual
 constraints :-)

 Nathann

 --
 You received this message because you are subscribed to the Google Groups
 sage-support group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to sage-support+unsubscr...@googlegroups.com.
 To post to this group, send email to sage-support@googlegroups.com.
 Visit this group at http://groups.google.com/group/sage-support.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Re: Binary variables in Integer Programs solved with CPLEX have wrong bounds

2014-01-07 Thread Stephen Hartke
On Tue, Jan 7, 2014 at 1:58 AM, Nathann Cohen nathann.co...@gmail.comwrote:

  Something is indeed wrong, and I have experienced similar problems in
 the past.  What version of CPLEX and which version of Sage are you using? I
 am using IBM ILOG CPLEX 12.5.1.0, and Sage 5.12 on Fedora Linux 19 and Sage
 5.10 on Fedora 13.

 HM... Well, to be honest I don't know. The truth is : I don't remember
 having met a nasty bug like that with Sage at any point, though it is
 possible that it may have been fixed since since you do not use the latest
 version of Sage.. Coud you try it with a more recent version of Sage, like
 the 6.0 ?


I upgraded to Sage 6.0, and the output is still wrong.  I then checked IBM,
and a new version of CPLEX was released in early December 2013.  With CPLEX
12.6.0 and Sage 6.0, I now get the correct answers.

So it seems that CPLEX 12.5.10 was the culprit.  Though it is surprising to
me that there would be such a basic bug.  I am somewhat worried that there
is something wrong with the CPLEX interface code in Sage, but it seems very
straightforward.

I recall having weird problems using CPLEX in Sage in the past; one
specific instance from summer 2012 jumps to mind.  I'll see if I can't dig
up one of those instances and see if they have been fixed with new versions
of Sage and CPLEX.


 Actually, there is a trac ticket waiting for review related to how LP
 solvers handle bounds, but I do not think it is related to this bug
 http://trac.sagemath.org/ticket/15622
 (it does *not only* fix GLPK code)


Do you mean http://trac.sagemath.org/ticket/14581 ?

Best wishes,
Stephen

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sage-support] Re: Binary variables in Integer Programs solved with CPLEX have wrong bounds

2014-01-06 Thread Stephen Hartke
Sorry for the delay in responding, but I was traveling over the holidays.
 Happy New Year!

On Sun, Dec 15, 2013 at 5:18 AM, Nathann Cohen nathann.co...@gmail.comwrote:

 {0: 2.0, 1: 0.0}

 Note that x[0] has the solution 2, which shouldn't happen for a binary 
 variable.

 When I ran the example of code you gave (removing the comment before
 binary=True, I get the solution 0:1, 1:1, which is good. If you really get
 a variable equal to 2 on this example, something is dead wrong indeed.


Something is indeed wrong, and I have experienced similar problems in the
past.  What version of CPLEX and which version of Sage are you using? I am
using IBM ILOG CPLEX 12.5.1.0, and Sage 5.12 on Fedora Linux 19 and Sage
5.10 on Fedora 13.


 Well, I would be glad to help but I would need to be able to reproduce one
 of the bugs for a start :-P


What other information can I give to help track this down?

Thanks,
Stephen

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.


[sage-support] Binary variables in Integer Programs solved with CPLEX have wrong bounds

2013-12-14 Thread Stephen Hartke
It seems that Integer Programs solved with CPLEX sometimes have the wrong
bounds on binary variables.  For instance,

p=MixedIntegerLinearProgram(solver=CPLEX)
x=p.new_variable(dim=1)  #,binary=True)
p.add_constraint(x[0]+x[1]==2)
p.set_objective(None)
p.set_binary(x)
p.show()
p.solve()
print p.get_values(x)

gives the output

Maximization:

Constraints:
  2.0 = x_0 + x_1 = 2.0
Variables:
  x_0 is a boolean variable (min=0.0, max=+oo)
  x_1 is a boolean variable (min=0.0, max=+oo)
{0: 2.0, 1: 0.0}

Note that x[0] has the solution 2, which shouldn't happen for a binary
variable.  In the output, the upper bound of the variable is not
printed correctly, but I'm not sure if that's a problem, since an
upper bound should not need to be explicitly set for a binary
variable.  In other instances when using binary variables with CPLEX,
they seem to behave as they should.

This issue is more problematic than it appears, since if CPLEX is
installed it becomes the default IP/LP solver, and other things can
randomly fail.  For instance,

sage.combinat.integer_vector.gale_ryser_theorem([2]*5,[5]*2)

should give a 5x2 matrix of all 1's but instead gives

[2 0]
[2 0]
[1 1]
[0 2]
[0 2]

I am using Sage 5.12 and IBM ILOG CPLEX 12.5.1.0.  I took a look in
cplex_backend.pyx, but nothing immediately jumped out as a problem.

Thanks for any insight that anyone has!

Best wishes,

Stephen

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sage-support] Bug in edge_cut of undirected weighted graphs

2012-04-02 Thread Stephen Hartke
Doug, thanks for the smaller example!  The bug may be dependent on the
labels of the vertices, as all the similar small examples I tried to create
worked successfully with edge_cut.

I've created a trac request: ticket
12797http://trac.sagemath.org/sage_trac/ticket/12797
.

Best wishes,
Stephen

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Bug in edge_cut of undirected weighted graphs

2012-03-24 Thread Stephen Hartke
While generating subtour elimination constraints for a traveling salesman
problem, I bound a bug in the edge_cut method for undirected weighted
graphs.  Specifically, when using the Ford-Fulkerson method, the value of
the minimum cut is correct, but sometimes the returned edge cut does not
have that value.  The LP method for edge_cut does seem to always return the
correct answer.

Attached is a simplified graph demonstrating the problem; it occurs in Sage
4.8.  I can also generate many more counterexamples from the TSP problem,
but the graphs are quite large.

Related trac tickets include 9852, 9350, and 7599, but those have all been
resolved.

Best wishes,
Stephen

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


example_bad_edge_cut.sage
Description: application/kdeuser1


example_bad_edge_cut.output
Description: Binary data


Re: [sage-support] Re: Exporting Sage notebook worksheet to SageTeX?

2012-02-10 Thread Stephen Hartke
Ivan and Karl,

Thanks for pointing out Huss and Marik's sws2tex!  That's mostly what I
want.  As discussed on ask.sagemath.org, there are some problems:
with solutions: turning off syntax highlighting, turning off the attach
file, saving the TeX file
no (yet!) solutions: aligns of equations are not converted correctly
other problem I found: \$ and \% are not handled correctly (which is a big
problem when discussing financial math!)

On Thu, Feb 9, 2012 at 10:39 AM, kcrisman kcris...@gmail.com wrote:

 I've started trying to make some of the code then into SageTeX blocks,
 but didn't get very far because I haven't used SageTeX enough to know
 what I want to do.  If you are pretty used to SageTeX, it should be a
 very short script or search/replace to change things into what you
 like.   But you might not even need it, since the outputs and inputs
 are all there...


It is convenient not to need to redo the computation, but it somehow feels
cleaner to use SageTeX to just redo the computation (nothing is too
complicated).  One problem I have is that the notebook captures print
commands, while I haven't figured out a way to do that in SageTeX.

Thanks everyone for your help!
Stephen

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Exporting Sage notebook worksheet to SageTeX?

2012-02-08 Thread Stephen Hartke
I've been writing a series of handouts for my class.  When writing them, I
like to initially use the Sage notebook as it allows me to quickly and
easily experiment with different examples, while still writing most of the
explanations.  However, for various reasons I'd like to be able to post pdf
versions or handout printed versions for my students.  Is it possible to
export a Sage notebook worksheet to SageTeX?  That would be great!  The
output from SageTeX I think looks better than printing from a browser, and
it is also allows more substantial LaTeX (and also easier to write, since a
TeX editor can be used) than jsMath does in the comment boxes.

I could not immediately find a feature to export to SageTeX.  If such a
feature does not already exist, how hard would it be to implement it?

Thanks!
Stephen

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Exporting Sage notebook worksheet to SageTeX?

2012-02-08 Thread Stephen Hartke
On 2/8/12 10:30 PM, Stephen Hartke wrote:

 I could not immediately find a feature to export to SageTeX.  If such a
 feature does not already exist, how hard would it be to implement it?


On Wed, Feb 8, 2012 at 10:37 PM, Jason Grout jason-s...@creativetrax.comwrote:

 I don't think it exists, but shouldn't be that hard.  Just get the text
 version of the worksheet (the Edit view) and:

 Replace

 {{{
 INPUT
 ///
 OUTPUT
 }}}

 with

 \begin{sageblock}
 INPUT
 \end{sageblock}

 (or use whatever sagetex environment you like)

 I guess it would be a bit harder to convert the text cells' html to latex,
 but should be doable.  But that would be about it, I think.


Jason,

Thanks for the suggestion!  I'd forgotten about getting the text version.
I'll try writing a script to replace input boxes as well replace the common
html with equivalent LaTeX (ie, replace em./em with
\emph{}).  If it seems useful, I'll share it once it's working.

Best wishes,
Stephen

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] sagetex and combinatorial graphs

2011-03-13 Thread Stephen Hartke
On Sun, Mar 13, 2011 at 12:08 AM, pong wypon...@gmail.com wrote:

 A quick question. How to use sagetex to display a graph (edges and
 vertices) produced by sage without saving it first manually then
 \includegraphics.


Plotting graphs works by calling sageplot on the graph's plot:

\sageplot{graphs.PetersenGraph().plot()}

The example.tex included with sagetex has more elaborate examples.

Best wishes,
Stephen

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Word-wrap in printed notebook worksheets

2011-02-17 Thread Stephen Hartke
When using the Print feature on a worksheet in the notebook, a new webpage
is generated for easy printing of the new worksheet.  In the to print
worksheet, the word wrap of the output text is fixed at something less than
70, resulting in short output lines when printed.  This wastes a lot of the
width of the paper.  Is there some way to change the length of the output
lines that are word wrapped when printing?

I just recently discovered how to change the default length of output lines
that are word wrapped in the notebook (when logged in as admin, go to
Settings, then Notebook settings), and it works great when using the
notebook, but this setting does not seem to carry over to the to print
pages.

Thanks for any insights!
Stephen

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Labeled Graphs

2010-11-28 Thread Stephen Hartke
On Wed, Nov 24, 2010 at 2:20 PM, Minh Nguyen nguyenmi...@gmail.com wrote:

 But I can't figure out how to get G.show() to display the edge weights.


You can just call G.show(edge_labels=True), which displays the vertex names
(by default) and the edge labels.  Of course, the layout is whatever the
spring embedder gives you (which doesn't take into account sizes of labels)
so things might be hard to read.  As a just-figuring-out-what's-going-on
tool, it's great, but for inclusion in a paper, you probably want to
manually set the vertex positions, or directly create the graph drawing with
matplotlib/graphviz/etc.

Best wishes,
Stephen

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Potential memory leak when calling binomial

2009-07-26 Thread Stephen Hartke
On Sun, Jul 26, 2009 at 12:31 AM, Carlo Hamalainen 
carlo.hamalai...@gmail.com wrote:

 On Sat, Jul 25, 2009 at 5:08 PM, Stephen Hartkehar...@gmail.com wrote:
  Might this be related to how binomial is evaluated using GiNaC?


 Valgrind says yes:

 ==26568== 4 bytes in 1 blocks are definitely lost in loss record 35 of
 3,312


The funny thing is that Valgrind detected _only_ 4 bytes that are definitely
lost.  So it doesn't seem that this particular memory leak can account for
the large amount of memory usage.

Stephen

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Potential memory leak when calling binomial

2009-07-25 Thread Stephen Hartke
The following code ends up using a lot of memory:

print get_memory_usage()
for i in range(10):
b=binomial(5,2)
print get_memory_usage()

Output:
133.48828125
135.015625

So 1.5 extra megabytes is used after the 100,000 calls of binomial.  If
repeated calls to binomial are made, eventually Sage runs out of memory and
bombs out.  This is a problem for the Combinations.rank() code, which makes
many repeated calls to binomial.

Might this be related to how binomial is evaluated using GiNaC?  Similar
problems occur when replacing binomial with log.

Weirdly, the code above with fixed parameters for binomial does not create a
problem when run in the notebook.  However, if different random values are
used in the binomial code for each iteration, then the same memory usage
occurs.  Perhaps there's some sort of caching going on?

I've tried this code on both Sage 4.0.1 and Sage 4.1, and the behavior is
the same.

Thanks for any insights!
Stephen

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Potential memory leak when calling binomial

2009-07-25 Thread Stephen Hartke
On Sat, Jul 25, 2009 at 1:54 PM, Justin C. Walker jus...@mac.com wrote:

 I just tried this on 4.0.2 and 4.1 (on Mac OS X, 10.5.7), and got the
 same values before and after the loop, so something else must be
 involved.


Justin,

Thanks for your response!  Did you run it from the command line or the
notebook?  I noticed that in the notebook, the code does create a problem,
but random values do.

Can you try the following code?

import random
print get_memory_usage()
for i in xrange(10):
x=random.randint(10,100)
y=random.randint(0,x)
r=binomial(x,y)
print get_memory_usage()

I tried the above code on sagenb.org, and get this output:

730.6328125
736.5625

I have Sage 4.1 on a Fedora 9 32-bit machine, and Sage 4.0.1 on a Fedora 8
64-bit machine.  I wonder if that's creating a problem.

Thanks for your help!
Stephen

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Potential memory leak when calling binomial

2009-07-25 Thread Stephen Hartke
On Sat, Jul 25, 2009 at 6:04 PM, Justin C. Walker jus...@mac.com wrote:

  I noticed that in the notebook, the code does create a problem,
 ^ not??
  but random values do.


Yes, I missed a not.


 Yup.  I now see what you see: memory usage increases after executing
 the loop using random values.  Go ahead and write up a trac/bug
 report, and thanks for reporting this.


This is now trac #6623 http://trac.sagemath.org/sage_trac/ticket/6623.

Thanks,
Stephen

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: showing the status of a computation without generating long output

2009-02-25 Thread Stephen Hartke
On Wed, Feb 25, 2009 at 6:52 AM, Marco Streng marco.str...@gmail.comwrote:

 I'm doing a long computation in Sage and I'd like to be able to print
 some status information to the screen, such as the number of database
 entries that I have tested, or the total time spent on different parts
 of an algorithm.


I had the same problem, and I now use the screen command. It essentially
multiplexes a text terminal (which is useful for running Sage in the
background after you log off, or being able to view/control the process
remotely), but can also be used to create a long scrollback buffer or for
logging the screen output to a file.  The last is very handy, since then you
have a record of the commands inputted to Sage and the output.  Also, you
can set the delay for how often the log buffer is flushed.  Thus, if you
have a process that outputs just a small update periodically, you don't have
to wait until the disk buffers are flushed to see the latest output.

Bets wishes,
Stephen

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: NB to pdf

2009-02-02 Thread Stephen Hartke
On Mon, Feb 2, 2009 at 10:04 AM, Jason Grout jason-s...@creativetrax.comwrote:


 kcrisman wrote:
  I don't believe that turning a notebook worksheet into a pdf is
  implemented (and thanks to Dan D. for SageTeX, which unfortunately


I have been printing worksheets to PDF files using my web browser as William
suggested.  I think this is an easy and immediate solution, and it also
works very well for students.

I have a few issues about this, though, that I discussed with Jason in DC at
the Joint Meetings.  This seems like a good time to bring them up.  First,
let me point out that I have not tried out TinyMCE, so I don't know how this
would affect things.

Here's a sample that I created to show the problems:
http://www.math.unl.edu/~shartke2/files/ConvertToPDFTest.pdf

1) As you can see, the font is huge, and very little can fit on a page.  Is
there any way to adjust the font size?  I have noticed that Sage webpages
are not very responsive to changing the web browser's text size.  Is this a
problem with the CSS?  In Firefox on Linux, changing the font size on screen
seems to have no effect on the printed output.  Also, is there an easy way
to change the length before wrapping occurs (but still have wrapping)?

2) Note that the %hide boxes still appear, but the %hideall boxes do
not.  It would be handy if there was a compromise between these: a box that
was hidden for printing, but was easy to change while editing (the problem I
find with %hideall boxes is that after saving a worksheet, there is no
easy way to go back and change the %hideall box).

Thanks for any help!
Stephen

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: integer linear programming in Sage?

2008-10-07 Thread Stephen Hartke
I have created a spkg to install lp_solve into Sage; it can be obtained at:
http://www.math.unl.edu/~shartke2/files/lp_solve-5.5.0.13.spkg
I have posted to sage-devel suggesting this spkg for inclusion into Sage.

lp_solve includes a linear programming solver (simplex based) and an integer
programming solver (branch and bound).  The IP solver is strong enough to
solve problems up to about 100 variables (give or take, depending on the
problem). lp_solve comes with Python bindings, and their online
documentation is very clear.

GLPK also has 2 sets of nice Python bindings: python-glpk at
http://www.dcc.fc.up.pt/~jpp/code/python-glpk/
and PyGLPK at
http://www.cs.cornell.edu/~tomf/pyglpk/

PyGLPK was just updated to work with the latest version of GLPK.  I believe
that work is ongoing to make python-glpk compile with the very latest
version of GLPK.

I hope to make a spkg for GPLK and these Python bindings at some point,
though seeing how this semester is going, it's probably not going to be
anytime soon.

Best wishes,
Stephen

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Questions about Matrices and Solving Linear Systems

2008-09-30 Thread Stephen Hartke
Hi!  I have some questions about matrices and solving linear systems of
equations.  These issues arose out of my using Sage for examples in my
Linear Optimization class (it's great for demonstrating how the simplex
algorithm works!) and for research I'm doing involving finite fields.

If I have a matrix A defined over some finite field, and a vector b over the
same finite field, what's the easiest way to solve the equation Ax=b?  Is
there any easy way to augment A with b as an extra column?  Is there an easy
way to insert a row or column?  Is there an easy way to delete a row or
column? The same questions apply for matrices over the rationals.

The functions stack() and insert_row() are pretty useful, but they seem to
be only defined for matrices over the integers.

Thanks for any help,
Stephen

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Question about calling Cython code

2008-04-30 Thread Stephen Hartke
Thanks for the information!  Using Integer=int has fixed most of my
problems.  Turning off the preparser prevents load cfuncs.spyx from
working, so I haven't been using that.

The main problem in my code, I discovered, was the use of Python lists and
numpy arrays.  By accessing the contents of the numpy arrays directly in
Cython, I found that my code ran about 1,000 times faster.  I remember
hearing that there might soon be new Cython features that would allow fast
access to numpy arrays.  Is that work still in progress?

Best wishes,
Stephen

On Fri, Apr 25, 2008 at 9:03 AM, William Stein [EMAIL PROTECTED] wrote:


 On Fri, Apr 25, 2008 at 6:56 AM, Stephen Hartke [EMAIL PROTECTED] wrote:
  I currently have some Sage code in a file called main.sage. I call this
 from
  the Sage command line interpreter with load main.sage.  After
 profiling my
  code, I moved a few functions into a cfuncs.spyx which I call with a
 load
  cfuncs.spyx command in main.sage.  This works great, and cfuncs.spyx is
  automatically compiled when I load main.sage.
 
  However, I have been having difficulty with the casting between Python
 ints,
  numpy int32s, and Sage integers.  Besides type casting problems, this
 also
  seems to significantly reduce the speed of my code. Is there a way to
  prevent Sage from wrapping constants with Integer()?

 You can write

Integer = int
n  = 5

 somewhere, and then the wrapping has no effect.
 You could also just explicitly put
   n = int(5)
 and then the wrapping is undone.
 Finally, you can put an r after any integer literal to make it raw,
 and then it won't be preparsed at all:
n = 5r
 Another option is just to give the command
   preparser(False)
 to completely turn off the preparser.

 All the same above comments apply for floating point literals as well.



   Alternatively, is
  there a way to call a Cython .pyx file from within a Python .py file
 (all
  running inside Sage, of course)?
 

 


--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Question about calling Cython code

2008-04-25 Thread Stephen Hartke
I currently have some Sage code in a file called main.sage. I call this from
the Sage command line interpreter with load main.sage.  After profiling my
code, I moved a few functions into a cfuncs.spyx which I call with a load
cfuncs.spyx command in main.sage.  This works great, and cfuncs.spyx is
automatically compiled when I load main.sage.

However, I have been having difficulty with the casting between Python ints,
numpy int32s, and Sage integers.  Besides type casting problems, this also
seems to significantly reduce the speed of my code. Is there a way to
prevent Sage from wrapping constants with Integer()?  Alternatively, is
there a way to call a Cython .pyx file from within a Python .py file (all
running inside Sage, of course)?

Thanks!
Stephen

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---