Problem in using Pulp

A

amitsoni.1984

Hi,
I am trying to run the following example which uses PULP for linear
optimization. But I am getting this error in the last line: "EOL while
scanning single quoted string".

Can anyone help me with this?
thanks
Amit

----------------------------------Code----------------------------
from pulp import *

prob = LpProblem("linear", LpMinimize)

# Variables
x = LpVariable("x", 0, 4)
y = LpVariable("y", -1, 1)
z = LpVariable("z", 0)

# Objective
prob += x + 4*y + 9*z

# Constraints
prob += x+y <= 5
prob += x+z >= 10
prob += -y+z == 7

GLPK("C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\").solve(prob)
 
R

Robert Kern

Hi,
I am trying to run the following example which uses PULP for linear
optimization. But I am getting this error in the last line: "EOL while
scanning single quoted string".
GLPK("C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\").solve(prob)

Backslashes escape characters in strings. Specifically, when a string uses ""
quotes as delimiters, then \" is the escape sequence for a double quote in the
string itself. The parser sees your \" at the end as simply an escaped double
quote and keeps interpreting the rest of the line as a string. Since the line
ends before another, unescaped " comes along, it raises the exception that you see.

http://docs.python.org/ref/strings.html

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
A

amitsoni.1984

Thanks, now I am not getting that error, but now I am getting a
different error:
---------------------error-------------------------------
GLPK("C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 114,
in solve
return lp.solve(self)
File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line
1740, in solve
status = solver.actualSolve(self)
File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 188,
in actualSolve
raise "PuLP: cannot execute "+self.path
PuLP: cannot execute C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples"
-------------------------------------------------------------
can anyone tell me where the problem is? I am using following code.
thanks
Amit
----------------------Code----------------------
from pulp import *

prob = LpProblem("linear", LpMinimize)

# Variables
x = LpVariable("x", 0, 4)
y = LpVariable("y", -1, 1)
z = LpVariable("z", 0)

# Objective
prob += x + 4*y + 9*z

# Constraints
prob += x+y <= 5
prob += x+z >= 10
prob += -y+z == 7

GLPK("C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
------------------------------------------------------------------------------
 
R

Robert Kern

Thanks, now I am not getting that error, but now I am getting a
different error:
---------------------error-------------------------------
GLPK("C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)
File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 114,
in solve
return lp.solve(self)
File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line
1740, in solve
status = solver.actualSolve(self)
File "C:\Documents and Settings\Amit\Desktop\pulp\pulp.py", line 188,
in actualSolve
raise "PuLP: cannot execute "+self.path
PuLP: cannot execute C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples"
GLPK("C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\"").solve(prob)

The last character in that string is a double quote. You don't want that. What
you want to do is escape all of the backslashes (or use raw strings to avoid the
escaping altogether). E.g.

"C:\\Documents and Settings\\Amit\\Desktop\\glpk-4.9\\glpk-4.9\\examples\\"

or

r"C:\Documents and Settings\Amit\Desktop\glpk-4.9\gplk-4.9\examples\"

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
H

Hendrik van Rooyen

GLPK("C:\Documents and
Settings\Amit\Desktop\glpk-4.9\glpk-4.9\examples\").solve(prob)
^*

* This is a no no - the backslash escapes the last quote...

- Hendrik
 
M

MRAB

Robert said:
The last character in that string is a double quote. You don't want that. What
you want to do is escape all of the backslashes (or use raw strings to avoid the
escaping altogether). E.g.

"C:\\Documents and Settings\\Amit\\Desktop\\glpk-4.9\\glpk-4.9\\examples\\"

or

r"C:\Documents and Settings\Amit\Desktop\glpk-4.9\gplk-4.9\examples\"
The second example won't work: you can't have a final backslash in a
raw string!
 
R

Robert Kern

MRAB said:
Robert Kern wrote:
The second example won't work: you can't have a final backslash in a
raw string!

My apologies. You are correct.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top