0

I wanted to use pyscipopt and I keep getting this error: OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\Program Files\SCIPOptSuite 8.0.3;D:\softwares\scip-8.0.3\bin'

`

 import pyscipopt
 

 model = pyscipopt.Model()

 # Set the solver parameters (optional)
 model.setParam('presolving/maxrounds', 0)  # Disable presolving 
 to solve the model as-is

 # Define the variables
 n = 3  # Number of rows
 m = 4  # Number of columns
 x = [[model.addVar(vtype='B', name=f'x_{i}_{j}') for j in 
 range(m)] for i in range(n)]


 z3 = 0
  for i in range(n):
     for j in range(m):
         f_i = ...  # Define your objective coefficient f_i for 
   variable x_i_j

    z3 += f_i * x[i][j]
   model.setObjective(z3, sense='minimize')

   model.optimize()


  if model.getStatus() == 'optimal':
  # Get the optimal solution
solution = [[model.getVal(x[i][j]) for j in range(m)] for i in 
  range(n)]
    print('Optimal solution:')
      for i in range(n):
          for j in range(m):
            print(f'x_{i}_{j} = {solution[i][j]}')
  else:
       print('No feasible solution found.')

   model.freeProb()
   `           
4
  • Are you using any paths in your code? Could you provide the code that causes this error?
    – ands
    Commented Jul 8, 2023 at 23:57
  • no, i'm not using any paths in my code Commented Jul 10, 2023 at 12:13
  • I tried your code, I set f_i = 1 so I got a trivial solution, but I didn't have any errors. Are you sure you installed PySCIPOpt properly? On their README page, they warn NOT to install PySCIPOpt in the Conda base environment.
    – ands
    Commented Jul 10, 2023 at 18:58
  • so please, where should i install it? Commented Jul 11, 2023 at 12:48

1 Answer 1

1

You need to create a new Conda environment. Open a terminal (on Windows you can use cmd (Command Prompt) or PowerShell) or Anaconda Prompt. To create an environment type in terminal:

conda create --name myenv

Name myenv is the name of your environment, you can put whatever you want, usually it is something like your project name. (You can also specify which Python version you want to use, for example conda create --name myenv python=3.11.) Then you need to activate the environment you just created so we can use it to run your program:

conda activate myenv

Before running the program we need to install package PySCIPOpt, we will use the command recommended in PySCIPOpt's README:

conda install --channel conda-forge pyscipopt

To run your program, you need to navigate to the folder (Windows logo, Ubuntu logo) where your program is located and then run your program with the command:

python programName.py

Filename programName.py is the name of your program.

This is a simple way to run your program from the terminal, if you are using an IDE then you can set up Anaconda with your IDE.

Not the answer you're looking for? Browse other questions tagged or ask your own question.