Showing posts with label Linear Programming. Show all posts
Showing posts with label Linear Programming. Show all posts

Tuesday, June 2, 2009

OWFS, GLPK, and Python

OWFS: Two weeks ago I installed OWFS and got it working with the sensors from the command line. This week I experimented with the python bindings to OWFS. Via Python I could easily connect to the sensors and read the temperature. What seemed difficult via the Python bindings was changing the temperature scale from the default of Celsius to common weather temperature of Fahrenheit. Via the command line this was an easy task, via Python binding it was a perplexing situation. After reading the documentation it appears the Python binding is not full featured enough to do this. So I figured I could write a simple Python line to issue the command line setting to complete this task. What prevent this was the binding to OWFS did not leave an obvious path to make this change and did not provide a command to find the path. So my conclusion was to write a Python script where half of it issues commands to the OS as if it were a shell script and then pull the data into Python logging and graphing. Below are some examples of what I needed I needed to do.

First I have to mount the file system for the controlling device. Since this is a USB device I need to do this as root. For now I just run my IDE Eric4 via gksudo until I can think of a better way
os.system('/opt/owfs/bin/owfs -u /var/1-wire/mnt')
So next I enumerate the interfaces on the wire
dirlist = os.popen('ls /var/1-wire/mnt/alarm/').read()
print "these are the interfaces"
print dirlist
PreIfaces = dirlist.split('\n')
IfaceLst = []
for listing in PreIfaces:
if re.match('10\.\w', listing):
print listing, "is a single interface"
listing = str(listing)
IfaceLst.append(listing)
So here is where I change the temperature scale and then see if my change took place

os.system('echo "F" > /var/1-wire/mnt/settings
/units/temperature_scale')
TempScale = os.system('cat /var/1-wire/mnt
/settings/units/temperature_scale && echo')
print TempScale
The rest of my code is learning the best (or most Pythonic) way to pass the list to the function os.popen so I can programmaticly get a temperature on all three interfaces without having to name each one. I think I will also just log the data to three text files using the CSV module for this current version. Then for version 2 of the script I may move logging to SQLite. I have the book
Beginning Python Visualization for guidance with making graphs in Python.

GLPK: So on the Ubuntu Linux machine I got PyMathProg installed. In my past post I stated I had the PyMathProg installed but that was the earlier version (since it was an Ubuntu package), that does not work with the examples on the current PyMathProg site: http://pymprog.sourceforge.net/. So tonight I uninstalled the Ubuntu package version and installed the version from the tarball I downloaded. Then I ran the basic PyMathProg examples and it seems to work now. So give another cheer for progress.

Thursday, May 7, 2009

Ubuntu: New software packages installed

As a follow up to my previous post, I just installed GNU Linear Programming Kit (GLPK) and PyMathProg. GLPK is recommended by Larry of http://industrialengineertools.blogspot.com/ and PyMathProg is a Python implementation of GLPK. I also installed SimPy which is a Python queuing simulation modeler. At some point, after I build a core set of skills, I will provide samples of theses programs in the blog.

Tuesday, April 28, 2009

OpenOpt, got some code to "run".

I made a little progress on OpenOpt. I got some code to "run". Now I need to spend some time to find how it can give me the same results as the same model in Excel. My latest OpenOpt Post shows my current state.

Thursday, April 16, 2009

OpenOpt and I started following someone's Blog

So I carved out a little more time to work with OpenOpt. I ran a built-in example named lp_1.py, since it was a Linear Programming example. By default the example script calls on a solver that is not included with the install of OpenOpt . Below is the line of code. The funny part is read the comment next to it and ponder why would this line be the default?

r = p.solve('cvxopt_lp') # CVXOPT must be installed

Any way you can see my current progress here.

On my journey to find why the example problem did not work by default, I found another blog that has similar interests to mine. Except this blogger seems to have experience in Operations/Decision Science vs. where I am just at the beginning of this journey. So I added myself as a follower to his blog: http://industrialengineertools.blogspot.com/

A good example of where we seem to be of similar interest is this article: http://industrialengineertools.blogspot.com/2009/02/does-software-hinder-innovation-in.html
I look forward to catching up with some of his other posts and future content.

Friday, April 10, 2009

Attempting OpenOpt

I decided to try using Python with OpenOpt, but I ran into a little issue with the module. You can see the bug report I filed with the OpenOpt forum. While on the forum site I found there are discussions for Linear problems, Network (mathematical not digital) problems, and Stochastic problems. These are all topics covered under Operations Management. After I get my OpenOpt install figured out, I will start with reviewing the Linear problems to see how I can build skills and participate in the forum.

Python Numpy/Scipy OpenOpt

I am still making slow progress on reading and comprehending The Science of Decision Making given various time constraints. But progress is being made. As I am building my Linear Programing (LP) knowledge I decided to seek out how I could perform LP with Python. For now, the OpenOpt library seems to be the most documented way. Here is an example of using the library for LP. Since my current book focuses on Excel, I am looking to transfer the example from the book to Python to compare the results. I know I keep repeating myself on what I plan to do, but blogging about this has the following advantages: 1) Let's you know I have not lost interest 2) Allows me to keep a document of my developing thoughts in a central place 3) Forces me to think through my plan to build operations management skills.

Thursday, March 26, 2009

Linear Programmers are Sensitive

I am have been slowly making my way through the book The Science of Decision Making and also using my old Operations Management textbook to gain a deeper understanding of Linear Programming. While I have performed the graphical method of Linear Programing and have used the Solver in Excel to find an answer, I had not used the "Sensitivity Report" before.

The "Sensitivity Report" is feedback for the data model. Using it a data modeler can can compare the "shadow price" vs. the real price of an extra unit of production. If the real price is greater than the shadow price then the results of the model given is considered optimal. If the shadow price is higher than the real price of an extra unit of production then adjustments can be made to the model. Another bit of feedback the "Sensitivity Report" gives you is the range of units for each constraint before the answer would change. Hence the amount of change required to change the answer can be considered along with the shadow price to determine if the model should change and if so in which direction.

As I gain greater insight to how linear programming works, I hope to post some examples with real data. Also at this time I am using Excel as that is what both books use for examples. At some point I plan to try the same thing with SciPy's optimizer.