A mathematica program returns as an output a sum of cardinal sines. The first element of the vector is
-19.9959 Sinc[0.0418879 (0. + t)] Sinc[0.0897598 (-65. + u)]
The variable is saved in a text file; however, this has to be read in pyomo as a variable, so a StringReplace
is used to adapt this variable to python's grammmar
savedXPython =
Import["savedWindX.txt"] //
StringReplace[#, {"[" -> "(", "]" -> ")",
"t" -> "m.lammda[i]*180/np.pi", "u" -> "m.phi[i]*180/np.pi"}] &
Then, savedXPython was saved to another text file. However, an error appeared while working with pyomo; I asked here and the answer was to save the result in a json file instead of a text.
Export["savedWindXPython.txt", savedXPython];
Export["savedWindXPythonJ.json", savedXPython, "ExpressionJSON"];
Now, in the pyomo part, the text file was originally read as
g = open("savedWindXPython.txt","r")
b=f.readline()
g.close
later on, following this thread, the json has been read as
f = open("savedWindXPythonJ.json","r")
a=f.readline()
f.close
And then, the variable inside the pyomo code is defined as
def Wind_lammda_definition(model, i):
return m.Wind_lammda[i] == a
m.Wind_lammda_const = Constraint(m.N, rule = Wind_lammda_definition)
in the case of the json file or def Wind_lammda_definition(model, i): return m.Wind_lammda[i] == b m.Wind_lammda_const = Constraint(m.N, rule = Wind_lammda_definition
in the case of the original text file
The code however doesn't work. AttributeError: 'str' object has no attribute 'is_relational'
, the error which prevented me from just reading the variable from the text file also appears in the json case.
It seems that using the json format has not helped. Can someone tell me if the json implementation has been done wrong?