Repository: Pyomo/pyomo

Issue:
Unallowed character (~) found in CPLEX log file path/name.
I am getting 

    ValueError: Unallowed character (~) found in CPLEX log file path/name.
	For portability reasons, only [a-zA-Z0-9 :.-_] are allowed.

When trying to solve the following simple problem with both cplex 12.8 and 12.9.
This seems to be similar to #809

```python
from pyomo.environ import *
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.c = ConstraintList()
m.c.add(2 * m.x  + m.y >= 1)
m.o = Objective(expr=m.x*2 + m.y*2)

opt = SolverFactory('cplex')
results = opt.solve(m)
```

OS: Win10
Python: '3.6.7 |Anaconda, Inc.| (default, Dec 10 2018, 20:35:02) [MSC v.1915 64 bit (AMD64)]'
Pyomo: '5.6.1'


Discussion:
A change analogous to the one by the commit cbde088 used to resolve that issue also fixes this one!
in pyomo/solvers/plugins/solvers/CPLEX.py:65

```python
_validate_file_name.allowed_characters = r"a-zA-Z0-9 ~\:\.\-_\%s" % (os.path.sep,)
```
Hmm although for a more involved problem it seems that this introduces another bug, what I am getting is:

```
Solver script file=C:\Users\M2F0F~1.LAN\AppData\Local\Temp\tmpr65_bdcn.cplex.script
Solver log file: 'C:\Users\M2F0F~1.LAN\AppData\Local\Temp\tmpu1_57kp_.cplex.log'
Solver solution file: 'C:\Users\M2F0F~1.LAN\AppData\Local\Temp\tmp5ykgky25.cplex.sol'
Solver problem files: ('C:\\Users\\M2F0F~1.LAN\\AppData\\Local\\Temp\\tmp4i7doc_z.pyomo.lp',)

Welcome to IBM(R) ILOG(R) CPLEX(R) Interactive Optimizer 12.8.0.0
  with Simplex, Mixed Integer & Barrier Optimizers
5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5655-Y21
Copyright IBM Corp. 1988, 2017.  All Rights Reserved.

Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.

CPLEX> Logfile 'cplex.log' closed.
Logfile 'C:\Users\M2F0F~1.LAN\AppData\Local\Temp\tmpu1_57kp_.cplex.log' open.
CPLEX> New value for mixed integer optimality gap tolerance: 0.02
CPLEX> New value for default parallel thread count: 4
CPLEX> New value for time limit in seconds: 60
CPLEX> New value for strategy to gather statistics on the kappa of subproblems: 1
CPLEX> Parameter 'solver' does not exist.
```

However this might be due to the way I call the solver, I'll report back when I find out more.
This one is a bit more explainable. Specifically, it looks like the “solver” keyword is somehow being set on the options for your solver plugin. Just before you invoke the solve() method, you should print the “solver.options” object - it’s a dictionary on the solver object itself. CPLEX is complaining rightly that it doesn’t know about a “solver” option. So it hopefully won’t be too hard to figure out why it is being put into the Pyomo solver object options dictionary.

Jpw



On Mar 27, 2019, at 8:36 AM, mlangiu <notifications@github.com<mailto:notifications@github.com>> wrote:


Hmm although for a more involved problem it seems that this introduces another bug, what I am getting is:

Solver script file=C:\Users\M2F0F~1.LAN\AppData\Local\Temp\tmpr65_bdcn.cplex.script
Solver log file: 'C:\Users\M2F0F~1.LAN\AppData\Local\Temp\tmpu1_57kp_.cplex.log'
Solver solution file: 'C:\Users\M2F0F~1.LAN\AppData\Local\Temp\tmp5ykgky25.cplex.sol'
Solver problem files: ('C:\\Users\\M2F0F~1.LAN\\AppData\\Local\\Temp\\tmp4i7doc_z.pyomo.lp',)

Welcome to IBM(R) ILOG(R) CPLEX(R) Interactive Optimizer 12.8.0.0
  with Simplex, Mixed Integer & Barrier Optimizers
5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5655-Y21
Copyright IBM Corp. 1988, 2017.  All Rights Reserved.

Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.

CPLEX> Logfile 'cplex.log' closed.
Logfile 'C:\Users\M2F0F~1.LAN\AppData\Local\Temp\tmpu1_57kp_.cplex.log' open.
CPLEX> New value for mixed integer optimality gap tolerance: 0.02
CPLEX> New value for default parallel thread count: 4
CPLEX> New value for time limit in seconds: 60
CPLEX> New value for strategy to gather statistics on the kappa of subproblems: 1
CPLEX> Parameter 'solver' does not exist.


—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<https://github.com/Pyomo/pyomo/issues/923#issuecomment-477016983>, or mute the thread<https://github.com/notifications/unsubscribe-auth/APpNHMC1qpvcxICm85iZ32ROfCYCF9Guks5vax-SgaJpZM4cNHJ9>.

Yeah, that's what I assumed. I am working with different solving interfaces and seem to be puting the solver option into the wrong dictionary. Still need to find out where, but that's my problem! Thanks for the hint :)

Resolving patch:
diff --git a/pyomo/solvers/plugins/solvers/CPLEX.py b/pyomo/solvers/plugins/solvers/CPLEX.py
--- a/pyomo/solvers/plugins/solvers/CPLEX.py
+++ b/pyomo/solvers/plugins/solvers/CPLEX.py
@@ -62,7 +62,8 @@ def _validate_file_name(cplex, filename, description):
                 "CPLEX or remove the space from the %s path."
                 % (description, filename, description))
     return filename
-_validate_file_name.allowed_characters = r"a-zA-Z0-9 :\.\-_\%s" % (os.path.sep,)
+_validate_file_name.allowed_characters = r"a-zA-Z0-9 ~:\.\-_\%s" % (
+    os.path.sep,)
 _validate_file_name.illegal_characters = re.compile(
     '[^%s]' % (_validate_file_name.allowed_characters,))
 


Test patch: