0

In OPL for input set we are defining as given below:

tuple Damage_line_Nodes {
int value;
};

// Declare a set with a few tuples
{Damage_line_Nodes} Damage_line_Node = ...;

In python (we are trying to give the input to the OPL model using python code given below)

from doopl.factory import create_opl_model
# Data
Damage_Nodes = [
{8, 9, 12, 6, 19, 23, 24, 27, 30} 
]
my_set_list = list(Damage_Nodes)

model_path = "C:/Users/VCGA/opl/MEG/MEG.mod"

with create_opl_model(model=model_path) as opl:

opl.set_input("Damage_line_Node", Damage_Nodes)

opl.set_input('Damage_line_Node',my_set_list) 

opl.run()

Here's a explanation of the error we encountered -

 *** ERROR[GENERATE_001] at 795:25-42 C:/Users/VCGA/opl/MEG/MEG.mod: Cannot use type <value:int> for int.
*** ERROR[GENERATE_001] at 828:2-19 C:/Users/VCGA/opl/MEG/MEG.mod: Cannot use type <value:int> for int.
*** ERROR[GENERATE_001] at 837:2-19 C:/Users/VCGA/opl/MEG/MEG.mod: Cannot use type <value:int> for int.
Fatal Python error: Aborted

The error messages we are encountering indicate that there's a type mismatch in the OPL model between what is expected and what is being provided. Specifically, the OPL model is not accepting the type value:int as a valid type for int. Suggest that I use both OPL and Python to feed input to the OPL model using Python.

1 Answer 1

0

You may use a list of tuples like in https://github.com/AlexFleischerParis/zoodocplex/blob/master/zoocallopl.py

Buses=[
        (40,500),
        (30,400)
        ]

# Create an OPL model from a .mod file
with create_opl_model(model="zootupleset.mod") as opl:
    # tuple can be a list of tuples, a pandas dataframe...
    opl.set_input("buses", Buses)

    # Generate the problem and solve it.
    opl.run()

In your case, turn

Damage_Nodes = [
{8, 9, 12, 6, 19, 23, 24, 27, 30} 
]

into

Damage_Nodes = [
(8,), (9,), (12,) , (6,) , (19,) , (23,) , (24,) , (27,) , (30,), 
]
Sign up to request clarification or add additional context in comments.

1 Comment

To provide input to the OPL model, I have defined tuple -- tuple Damage_line_Nodes { int value; }; // Declare a set with tuple {Damage_line_Nodes} Damage_line_Node = ...; And this set is used in constraint given below ----forall (s in Slot:!(s==24)){ forall (rc in repair_crew){ forall (n in Damage_line_Node){ StatusLine[rc][n][s+1]<=sum(t in 1..s)CrewPos[rc][n][t]/2; } } }. The error in OPL mode is --- Cannot use type <value:int> for int. Suggest me the corrections in OPL model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.