I'm currently trying to implement a generic nurse rostering problem (NRP) in a branch-and-price framework in Python on Windows.
I tried using Gurobi, but apparently it isn't possible, see discussion:
https://support.gurobi.com/hc/en-us/community/posts/360043240312-Branch-and-price-example
I'm searching a small example on how to set up the branch-and-price framework using SCIP in Python - to get started. I could only find examples in C and C++, which are languages I'm not familiar with.
Please have a look at PySCIPOpt, which is the Python interface of SCIP. You find in PySCIPOpt/tests/test_pricer.py a column-generation-based example for the cutting stock problem. Still, I would recommend looking at the Binpacking example of SCIP.
Related
I have a system of stochastic differential equations implemented in MATLAB. Just 4 variables integrated with Euler-Maruyama, so nothing too fancy... the technical details aren't important for this question though.
How would you recommend I go about building a web interface (i.e., let people change the parameters and initial conditions in their web browser and then display the results)?
The first step should be translating the code to numpy/matplotlib, right?
Should I be saving the output as an image or doing some fancy HTML5 plotting stuff?
Are there any publicly available tools/frameworks that will make it easy to build a nice web UI for this kind of thing?
Any tips on where to host this kind of thing, or am I basically limited to setting up my own server?
If there are no constraints on the target language, I'd simply translate to R and use RApache. There are plenty of libraries to support this. In fact, you may not need to reimplement much code, given what's available in R libraries.
The reason I suggest R is that I've ported a lot of Matlab code to make it reusable or open, and R has usually been the easiest target for me, due to the libraries already developed.
EDIT/UPDATE: I overlooked using RStudio as a server. That might be the easiest way to go. See this page: http://www.rstudio.org/docs/server/getting_started.
Regarding where to set this up, you could look at using Amazon's "micro instances", if the amount of computation is very limited. There are also some new startups doing cloud stuff. One choice might be http://cloudnumbers.com/.
So, I'd recommend:
Post a question about the SDE stuff (to get pointers to the right package(s) on CRAN).
Install RStudio and play with the package
Try out RStudio server
Look for hosting :)
...
Profit! :) :)
I would not recommend saving stuff to disk and re-loading it. It's best to have things as smoothly coupled as possible, so that you don't have to code stuff to maintain a state on the server or browser side.
RStudio is quite cool if you want to take the R route. If you want to stick with Python, I recommend you to take a look at Femhub. It's perhaps the most mature and well developed web interface to do numerical computations in Python. Jut take a look to the "Published worksheets" examples to see what is capable of.
Is there any article/paper on what features the Python language has to offer? Why should one go with Python instead of any other language? What are the strong and the weak points of Python?
Why Python
and
Why Python
so
Choose Python (import this)
Probably the prime reason I use Python is because it's very good at self-documenting. There are lots of other reasons too, but probably the best way to find out is to do something with it. Find a project and see what it takes to do it in Python. It may not be great Python code, but you'll learn more about how it suits you than from an essay. I know the first time I looked at Python, I didn't give it much chance (just looked like Matlab as far as I was concerned), but after using it for a couple of years, I have to say I have no regrets.
Paul Prescod Why I Promote Python has many good points why python is a good choice.
Why Python? Because all the cool kids are doing it.
Disclaimer: I just noticed "popularity-contest" running on my machine so I investigated. Although quite useful for QA and planning, one can't actually derive any meaning from that graph which could at least as well be explained by the rise of Ubuntu installations and their Python based administrative tools. This link is for amusement purposes only, void in Idaho and Nebraska.
there is a year old, similar question - but in case there have been changes afoot:
i'm an intermediate c++ programmer just starting out on python, post some online tuts etc i can do some basic pythoneering, but was wondering if there are good places i can look online for simple(ish) --pref console based-- code that i can learn from, ideally with some sort of commentary.
anything come to mind?
thanks
The standard library is an excellent place to the start. It's maintained by the core python team and is of high quality with a lot of interesting idioms. I'd recommend the newer modules since they don't have much backward compatibility cruft and are more representative of the language as it is now. The older ones were written for earlier versions of Python and have some restrictions when it comes to API changes etc.
The list of modules in the standard library is described at http://docs.python.org/library/. You can go through it and decide which one you want to look at (area of interest etc.).
Their sources are viewable at the mercurial repo here http://hg.python.org/cpython/file/d7e85ddb1336/Lib (as of today). These are for the mainline 2.6 release. You can also checkout the repo and browse it on your local machine.
You can also start up your interpreter, import a module (say os) and do a print os.__file__ to see where the source file is if you want to look at the code in your local editor.
ActiveState Recipes is a good source for all kinds of Python scripts. But if you want to learn the basics of Python, you might just want to look at the standard library that ships with Python ("lib" directory").
i came across This The other day, Probably you can learn some python basics and have a laugh too!
Anyways, look at the libs as they said above, they are very useful
If you enjoy riddles:
www.pythonchallenge.com
If you're an intermediate C++ programmer, you're already equipped to handle to programming concepts. I like it because it gives me a reason to learn each part of the language, without being mundane 'Hello World' tasks.
However, some of the riddles are pretty tough and/or unrelated to programming. Either way, doing the first few will probably be enough to get your confidence up with Python syntax.
My machine has two audio inputs: a mic in that I use for gaming, and a line in that I use for guitar. When using one it's important that the other be muted to remove hiss/static, so I was hoping to write a small script that would toggle which one was muted (it's fairly inconvenient to click through the tray icon, switch to my input device, mute and unmute).
I thought perhaps I could do this with pywin32, but everything I could find seemed specific to setting the output volume rather than input, and I'm not familiar enough with win32 to even know where to look for better info.
Could anybody point me in the right direction?
Disclaimer: I'm not a windows programming guru by any means...but here's my best guess
Per the pywin32 FAQ:
How do I use the exposed Win32 functions to do xyz?
In general, the trick is to not
consider it a Python/PyWin32 question
at all, but to search for
documentation or examples of your
problem, regardless of the language.
This will generally give you the
information you need to perform the
same operations using these
extensions. The included
documentation will tell you the
arguments and return types of the
functions so you can easily determine
the correct way to "spell" things in
Python.
Sounds like you're looking to control the "endpoint device" volumes (i.e. your sound card / line-in). Here's the API reference in that direction.
Here's a slightly broader look at controlling audio devices in windows if the previous wasn't what you're looking for.
Here's a blog entry from someone who did what you're trying to do in C# (I know you specified python, but you might be able to extract the correct API calls from the code).
Good luck! And if you do get working code, I'm interested to see it.
I had a similar problem and couldn't figure out how to use Windows API's to do what I wanted. I ended up just automating the GUI with AutoIt. I think that will be the fastest and easiest solution (albeit a "hacky" one). As I answered earlier today, you can use AutoIT from within Python.
You are probably better off using ctypes - pywin32 is good if you are using one of the already included APIs, but I think you'll be out of luck with the sound APIs. Together with the example code from the C# link provided by tgray, use ctypes and winmm.dll, or alternatively, use SWIG to wrap winmm.dll. This may well be quicker as you won't have to build C structure mapping types in ctypes for the types such as MIXERCONTROLDETAILS which are used in the API calls.
tgray seems to have pointed you in the right direction, but once you find out the right Win32 APIs to deal with, you have a couple of options:
1) Try using pywin32...but it may or may not wrap the functionality you need (it probably doesn't). So you probably only want to do this if you need to use COM to get at the functionality you need.
2) Use ctypes. It's generally pretty easy to wrap just about any C functionality with ctypes.
3) If the C# example looks like what you need, you should be able to translate it to IronPython with fairly little effort. Might be easier than using the C API. YMMV, of course.
When digging into legacy Python code and writing Python code myself, I often use pylint. I'm also using Clone Digger. I've recently started to use rope, which is a library for automated refactoring.
But I'm looking for something else than rope. I would prefer a tool that just makes suggestions about possible refactorings: names the refactoring, optionally provides a short description of it (great for learning purposes), highlights the code section and lets me do the refactoring myself. Is there such a tool?
Check out bicycle repair man http://bicyclerepair.sourceforge.net/
What is Bicycle Repair Man?
The Bicycle Repair Man project is an attempt to create refactoring browser functionality for python. It is packaged as a library that can be added to IDEs and editors to provide refactoring capabilities. Bindings for Emacs and Vi are included with the package.
Never used it myself, but have read about it. Sounds like what you are looking for.
You might like Pythoscope, an automatic Python unit test generator, which is supposed to help you bootstrap a unit test suite by dynamically executing code.
Also, have you checked out the rope.contrib.codeassist module? It is supposed to automatically propose and perform refactorings of your source code for you.
I don't if that type of tool exists in any specific language, although the concept was mentioned in Martin Fowler's refactoring book (web reference).
The best tool I know of that currently exists is cyclomatic complexity. This article implements a cyclomatic complexity counter for python.
The other easy metric to target is method/function length, number of attributes of objects/classes and number of parameters to functions, if I recall, pylint already counted those.
Oh Forget about your tool, instead use TDD and a good book like refactoring to design patterns by Kerievsky. The problem is that refactoring is a way to improve your code and design, but only You can know what you want to achieve, no refactoring tool can do it for you.
My point is that best way to learn refactoring is to study examples, not to follow some stupid/simple tools, because they wont teach you any sophisticated refactoring nor they will tell you if you have refactoring that compose well with you code.
PS Read Fowler "Refactoring" and Kerievsky "Refactoring to design Patterns" those books are must read when learning refactoring. And they mention simple way to checking if refactoring is needed (smells).
Also consider TDD as good way to ensure that your refs are safe and do not break your code.
Beck "Test-Driven Development by example" is a good book to start with.
And Python have PyUnit for TDD.
NetBeans has an early access version that supports Python, and it is rather nice. It has some basic refactoring tools that I found the be useful. As an added bonus it works on Windows, Linux, Mac OS X and Solaris.
Check it out at:
http://www.netbeans.org/features/python/