Pulp obtains results as problem is infeasible, while problem is not feasible - python
I'm trying to solve an assignment problem with pulp. The basic part of the code is as follows:
set_I = range(1, numberOfPoints)
set_J = range(1, numberOfCentroids)
tau = 0.15
Q = 15
# decision variable
x_vars = LpVariable.dicts(name="x_vars", indexs=(set_I, set_J), lowBound=0, upBound=1, cat=LpInteger)
# model name
prob = LpProblem("MIP_Model", LpMinimize)
# constraints
for i in set_I:
prob += lpSum(x_vars[i][j] for j in set_J) == 1, ""
for j in set_J:
prob += lpSum(x_vars[i][j] for i in set_I) >= 1, ""
for j in set_J:
prob += lpSum(x_vars[i][j] for i in set_I) <= Q*(1-tau), ""
for j in set_J:
prob += lpSum(x_vars[i][j] for i in set_I) >= Q*(1+tau), ""
# objective
prob += lpSum(d[i, j]*x_vars[i][j] for i in set_I for j in set_J)
prob.solve()
The result is like this:
Problem MODEL has 31 rows, 76 columns and 304 elements
Coin0008I MODEL read with 0 errors
Problem is infeasible - 0.01 seconds
Option for printingOptions changed from normal to all
However, the problem is not infeasible and results are obtained with other solvers.
I wonder if there is a syntax error and is the problem caused by this?
I have asked a similar question in the next link:
Infeasible solution by pulp
When I run the problem locally, with d a matrix of ones, 20 points, and 3 centroids. It also becomes infeasible for me. Look at the constraints:
_C22: x_vars_10_1 + x_vars_11_1 + x_vars_12_1 + x_vars_13_1 + x_vars_14_1
+ x_vars_15_1 + x_vars_16_1 + x_vars_17_1 + x_vars_18_1 + x_vars_19_1
+ x_vars_1_1 + x_vars_2_1 + x_vars_3_1 + x_vars_4_1 + x_vars_5_1 + x_vars_6_1
+ x_vars_7_1 + x_vars_8_1 + x_vars_9_1 <= 12.75
_C23: x_vars_10_2 + x_vars_11_2 + x_vars_12_2 + x_vars_13_2 + x_vars_14_2
+ x_vars_15_2 + x_vars_16_2 + x_vars_17_2 + x_vars_18_2 + x_vars_19_2
+ x_vars_1_2 + x_vars_2_2 + x_vars_3_2 + x_vars_4_2 + x_vars_5_2 + x_vars_6_2
+ x_vars_7_2 + x_vars_8_2 + x_vars_9_2 <= 12.75
_C24: x_vars_10_1 + x_vars_11_1 + x_vars_12_1 + x_vars_13_1 + x_vars_14_1
+ x_vars_15_1 + x_vars_16_1 + x_vars_17_1 + x_vars_18_1 + x_vars_19_1
+ x_vars_1_1 + x_vars_2_1 + x_vars_3_1 + x_vars_4_1 + x_vars_5_1 + x_vars_6_1
+ x_vars_7_1 + x_vars_8_1 + x_vars_9_1 >= 17.25
_C25: x_vars_10_2 + x_vars_11_2 + x_vars_12_2 + x_vars_13_2 + x_vars_14_2
+ x_vars_15_2 + x_vars_16_2 + x_vars_17_2 + x_vars_18_2 + x_vars_19_2
+ x_vars_1_2 + x_vars_2_2 + x_vars_3_2 + x_vars_4_2 + x_vars_5_2 + x_vars_6_2
+ x_vars_7_2 + x_vars_8_2 + x_vars_9_2 >= 17.25
You require
x_vars_10_2 + x_vars_11_2 + x_vars_12_2 + x_vars_13_2 + x_vars_14_2
+ x_vars_15_2 + x_vars_16_2 + x_vars_17_2 + x_vars_18_2 + x_vars_19_2
+ x_vars_1_2 + x_vars_2_2 + x_vars_3_2 + x_vars_4_2 + x_vars_5_2 + x_vars_6_2
+ x_vars_7_2 + x_vars_8_2 + x_vars_9_2
to be greater than 17.25 and smaller than 12.75 at the same time. That's not possible, of course.
Related
argument must be a string or a number, not 'LpAffineExpression'
I am trying to use python IRR function with PULP maximisation but i am getting the following error TypeError: float() argument must be a string or a number, not 'LpAffineExpression' TypeError Traceback (most recent call last) in 11 name[6]*rate[6]*ratesList2[2] + name[7]*rate[7]*ratesList2[2] + name[8]*rate[8]*ratesList2[2] + name[9]*rate[9]*ratesList2[2] + name[10]*rate[10]*ratesList2[2] + name[11]*rate[11]*ratesList2[2] + 12 name[12]*rate[12]*ratesList2[2] + name[13]*rate[13]*ratesList2[2] + name[14]*rate[14]*ratesList2[2] + name[15]*rate[15]*ratesList2[2] + name[16]*rate[16]*ratesList2[2] + name[17]*rate[17]*ratesList2[2] + ---> 13 name[18]*rate[18]*ratesList2[2])]) 14 15 problem += np.irr([(-19660528.00), (name[0]*rate[0] + name[1]*rate[1] + name[2]*rate[2] + name[3]*rate[3] + name[4]*rate[4] + name[5]*rate[5] + name[6]*rate[6] + name[7]*rate[7] + name[8]*rate[8] + name[9]*rate[9] + name[10]*rate[10] + name[11]*rate[11] + name[12]*rate[12] + name[13]*rate[13] + name[14]*rate[14] + name[15]*rate[15] + name[16]*rate[16] + name[17]*rate[17] + name[18]*rate[18]), (name[0]*rate[0]*ratesList1[1] + name[1]*rate[1]*ratesList2[1] + name[2]*rate[2]*ratesList2[1] + name[3]*rate[3]*ratesList2[1] + name[4]*rate[4]*ratesList2[1] + name[5]*rate[5]*ratesList2[1] + name[6]*rate[6]*ratesList2[1] + name[7]*rate[7]*ratesList2[1] + name[8]*rate[8]*ratesList2[1] + name[9]*rate[9]*ratesList2[1] + name[10]*rate[10]*ratesList2[1] + name[11]*rate[11]*ratesList2[1] + name[12]*rate[12]*ratesList2[1] + name[13]*rate[13]*ratesList2[1] + name[14]*rate[14]*ratesList2[1] + name[15]*rate[15]*ratesList2[1] + name[16]*rate[16]*ratesList2[1] + name[17]*rate[17]*ratesList2[1] + name[18]*rate[18]*ratesList2[1]), (name[0]*rate[0]*ratesList1[2] + name[1]*rate[1]*ratesList2[2] + name[2]*rate[2]*ratesList2[2] + name[3]*rate[3]*ratesList2[2] + name[4]*rate[4]*ratesList2[2] + name[5]*rate[5]*ratesList2[2] + name[6]*rate[6]*ratesList2[2] + name[7]*rate[7]*ratesList2[2] + name[8]*rate[8]*ratesList2[2] + name[9]*rate[9]*ratesList2[2] + name[10]*rate[10]*ratesList2[2] + name[11]*rate[11]*ratesList2[2] + name[12]*rate[12]*ratesList2[2] + name[13]*rate[13]*ratesList2[2] + name[14]*rate[14]*ratesList2[2] + name[15]*rate[15]*ratesList2[2] + name[16]*rate[16]*ratesList2[2] + name[17]*rate[17]*ratesList2[2] + name[18]*rate[18]*ratesList2[2])]) problem += (name[0] + name[1] + name[2] + name[3] + name[4] + name[5] + name[6] + name[7] + name[8] + name[9] + name[10] + name[11] + name[12] + name[13] + name[14] + name[15] + name[16] + name[17] + name[18]) <= sum(marketMix['GLA']), "1st constraint"
The numpy function irr() takes as argument a list of values. You are instead passing a list of linear expressions containing variables that are subject to optimization. irr() is not prepared to handle that. It assumes that all arguments can be coerced into a float. Instead of using function irr() you will have to state the respective expression explicitly.
Expand parent prefix number to a given child number
I have a parent prefix number and a child number that begins with the same prefix. I want to expand the parent number up to the target child number in a way that all prefixes be included and show the target, for example. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + Example #1 + Example #2 + Example #3 + + parent=123, target=1235 + parent=123, target=12354 + parent=123, target=123073 + + + + + + Expansion would be: + Expansion would be: + Expansion would be: + + + + + + 123-0 + 123-0 + 123-0-0 + + 123-1 + 123-1 + 123-0-1 + + 123-2 + 123-2 + 123-0-2 + + 123-4 + 123-4 + 123-0-3 + + 123-5 --> target + 123-5-0 + 123-0-4 + + 123-6 + 123-5-1 + 123-0-5 + + 123-7 + 123-5-2 + 123-0-6 + + 123-8 + 123-5-4 --> target + 123-0-7-0 + + 123-9 + 123-5-5 + 123-0-7-1 + + + 123-5-6 + 123-0-7-2 + + + 123-5-7 + 123-0-7-3 --> target + + + 123-5-8 + 123-0-7-4 + + + 123-5-9 + 123-0-7-5 + + + 123-6 + 123-0-7-6 + + + 123-7 + 123-0-7-7 + + + 123-8 + 123-0-7-8 + + + 123-9 + 123-0-7-9 + + + + 123-0-8 + + + + 123-0-9 + + + + 123-1 + + + + 123-2 + + + + 123-3 + + + + 123-4 + + + + 123-5 + + + + 123-6 + + + + 123-7 + + + + 123-8 + + + + 123-9 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Like you see, In example #1, target is 4 digit length and only one level expansion was needed In example #2, target is 5 digit length and two level expansion was needed In example #3, target is 6 digit length and three level expansion was needed In my current code shown below, I'm only able to print one level expansion and only for one target. I'm stuck in how to expand the parent number when target length is greater in 2 or more digits compared with length of parent and if input targets are more than one. Help would be appreciated. parent="1312314" child="13123147674" l = len(parent) target=child[l:] t=int(target[0]) for k in range(t): print(parent + str(k)) print(parent + str(t) + " --> target") for k in range(t+1,10): print(parent + str(k)) Current output: 13123140 13123141 13123142 13123143 13123144 13123145 13123146 13123147 --> target 13123148 13123149 Update Example #4 parent=12345, target1=1234538, target2=1234570924, target3=123459 Expansion would be: 123450 123451 123452 1234530 1234531 1234532 1234533 1234534 1234535 1234536 1234537 1234538 --> target 1234539 123454 123455 123456 12345700 12345701 12345702 12345703 12345704 12345705 12345706 12345707 12345708 123457090 123457091 1234570920 1234570921 1234570922 1234570923 1234570924 --> target 1234570925 1234570926 1234570927 1234570928 1234570929 123457093 123457094 123457095 123457096 123457097 123457098 123457099 1234571 1234572 1234573 1234574 1234575 1234576 1234577 1234578 1234579 123458 123459 --> target
you can try this. the trick is result.sort() parent="123" child= "12354" p = len(parent) c = len(child) result = [] for i in range(p, c): for x in range(0, 10): y = child[0:i] + str(x) result.append(y) result.sort() for a in result: print (a + ("--> target" if a == child else "")) Result: 1230 1231 1232 1233 1234 1235 12350 12351 12352 12353 12354--> target 12355 12356 12357 12358 12359 1236 1237 1238 1239 for multiple targets: parent="12345" target1="1234538" target2="1234570924" target3="123459" targets = [target1, target2, target3] result = [] for target in targets: for i in range(len(parent), len(target)): for x in range(0, 10): y = target[0:i] + str(x) result.append(y) result = list(set(result)) result.sort() for a in result: print (a + ("--> target" if a in targets else ""))
u can do as below: parent='123' child='123073' if len(child)> len(parent): tuple_list =[] nums_to_append=child[len(parent):] l = len(nums_to_append) for i,num in enumerate(nums_to_append): for j in range(10): if num == str(j): tuple_list.append((parent,j+1)) parent = parent+num if i==(l-1): print(parent, "--> target") break else: print(parent+str(j)) for parent,num in tuple_list[::-1]: for j in range(num,10): print(parent+str(j)) 12300 12301 12302 12303 12304 12305 12306 123070 123071 123072 123073 --> target 123074 123075 123076 123077 123078 123079 12308 12309 1231 1232 1233 1234 1235 1236 1237 1238 1239
Generate a Bode-form transfer function using ratsimp
I have to simplify a transfer function using sympy. I am used to maxima and I am looking for advice to get similar performances in a python environment. Using the following Maxima code: A:-Avol0/(1+s/(2*pi*fp)); Zph:Rsh/(1+Rsh*Cj*s); Zf:Rf/(1+Rf*Cf*s); alpha:Zf*Zph/(Zf+Zph); beta:Zph/(Zf+Zph); BetaA:ratsimp(beta*A,s); H:ratsimp(alpha*A/(1-BetaA),s); I get the following: (H)-> -(2*Avol0*Rf*Rsh*fp*pi)/((Cj+Cf)*Rf*Rsh*s^2+((2*Cj+(2*Avol0+2)*Cf)*Rf*Rsh*fp*pi+Rsh+Rf)*s+((2*Avol0+2)*Rsh+2*Rf)*fp*pi) The same opertions in sympy do not get to such a nice result: import numpy as np import sympy as sy """ Formulas """ s, Rf, Cf, Rsh, Cj, Cd, Ccm, GBP, Avol0, fp, w = \ sy.symbols("s Rf Cf Rsh Cj Cd Ccm GBP Avol0 fp w") A = -Avol0/(1+s/(2*np.pi*fp)) Zph = Rsh/(1+Rsh*Cj*s) Zf = Rf/(1+Rf*Cf*s) alpha = Zf*Zph/(Zf+Zph) beta = Zph/(Zf+Zph) Gloop = sy.ratsimp(beta*A) H = alpha*A/(1-Gloop) sy.ratsimp(H) returns an unreadable result: -1.0*(1.0*Avol0*Cf**2*Cj*Rf**3*Rsh**3*fp**2*s**3 + 0.159154943091895*Avol0*Cf**2*Cj*Rf**3*Rsh**3*fp*s**4 + 1.0*Avol0*Cf**2*Rf**3*Rsh**2*fp**2*s**2 + 0.159154943091895*Avol0*Cf**2*Rf**3*Rsh**2*fp*s**3 + 1.0*Avol0*Cf*Cj**2*Rf**3*Rsh**3*fp**2*s**3 + 0.159154943091895*Avol0*Cf*Cj**2*Rf**3*Rsh**3*fp*s**4 + 2.0*Avol0*Cf*Cj*Rf**3*Rsh**2*fp**2*s**2 + 0.318309886183791*Avol0*Cf*Cj*Rf**3*Rsh**2*fp*s**3 + 2.0*Avol0*Cf*Cj*Rf**2*Rsh**3*fp**2*s**2 + 0.318309886183791*Avol0*Cf*Cj*Rf**2*Rsh**3*fp*s**3 + 1.0*Avol0*Cf*Rf**3*Rsh*fp**2*s + 0.159154943091895*Avol0*Cf*Rf**3*Rsh*fp*s**2 + 2.0*Avol0*Cf*Rf**2*Rsh**2*fp**2*s + 0.318309886183791*Avol0*Cf*Rf**2*Rsh**2*fp*s**2 + 1.0*Avol0*Cj**2*Rf**2*Rsh**3*fp**2*s**2 + 0.159154943091895*Avol0*Cj**2*Rf**2*Rsh**3*fp*s**3 + 2.0*Avol0*Cj*Rf**2*Rsh**2*fp**2*s + 0.318309886183791*Avol0*Cj*Rf**2*Rsh**2*fp*s**2 + 1.0*Avol0*Cj*Rf*Rsh**3*fp**2*s + 0.159154943091895*Avol0*Cj*Rf*Rsh**3*fp*s**2 + 1.0*Avol0*Rf**2*Rsh*fp**2 + 0.159154943091895*Avol0*Rf**2*Rsh*fp*s + 1.0*Avol0*Rf*Rsh**2*fp**2 + 0.159154943091895*Avol0*Rf*Rsh**2*fp*s)/(1.0*Avol0*Cf**3*Cj*Rf**3*Rsh**3*fp**2*s**4 + 0.159154943091895*Avol0*Cf**3*Cj*Rf**3*Rsh**3*fp*s**5 + 1.0*Avol0*Cf**3*Rf**3*Rsh**2*fp**2*s**3 + 0.159154943091895*Avol0*Cf**3*Rf**3*Rsh**2*fp*s**4 + 1.0*Avol0*Cf**2*Cj**2*Rf**3*Rsh**3*fp**2*s**4 + 0.159154943091895*Avol0*Cf**2*Cj**2*Rf**3*Rsh**3*fp*s**5 + 2.0*Avol0*Cf**2*Cj*Rf**3*Rsh**2*fp**2*s**3 + 0.318309886183791*Avol0*Cf**2*Cj*Rf**3*Rsh**2*fp*s**4 + 3.0*Avol0*Cf**2*Cj*Rf**2*Rsh**3*fp**2*s**3 + 0.477464829275686*Avol0*Cf**2*Cj*Rf**2*Rsh**3*fp*s**4 + 1.0*Avol0*Cf**2*Rf**3*Rsh*fp**2*s**2 + 0.159154943091895*Avol0*Cf**2*Rf**3*Rsh*fp*s**3 + 3.0*Avol0*Cf**2*Rf**2*Rsh**2*fp**2*s**2 + 0.477464829275686*Avol0*Cf**2*Rf**2*Rsh**2*fp*s**3 + 2.0*Avol0*Cf*Cj**2*Rf**2*Rsh**3*fp**2*s**3 + 0.318309886183791*Avol0*Cf*Cj**2*Rf**2*Rsh**3*fp*s**4 + 4.0*Avol0*Cf*Cj*Rf**2*Rsh**2*fp**2*s**2 + 0.636619772367581*Avol0*Cf*Cj*Rf**2*Rsh**2*fp*s**3 + 3.0*Avol0*Cf*Cj*Rf*Rsh**3*fp**2*s**2 + 0.477464829275686*Avol0*Cf*Cj*Rf*Rsh**3*fp*s**3 + 2.0*Avol0*Cf*Rf**2*Rsh*fp**2*s + 0.318309886183791*Avol0*Cf*Rf**2*Rsh*fp*s**2 + 3.0*Avol0*Cf*Rf*Rsh**2*fp**2*s + 0.477464829275686*Avol0*Cf*Rf*Rsh**2*fp*s**2 + 1.0*Avol0*Cj**2*Rf*Rsh**3*fp**2*s**2 + 0.159154943091895*Avol0*Cj**2*Rf*Rsh**3*fp*s**3 + 2.0*Avol0*Cj*Rf*Rsh**2*fp**2*s + 0.318309886183791*Avol0*Cj*Rf*Rsh**2*fp*s**2 + 1.0*Avol0*Cj*Rsh**3*fp**2*s + 0.159154943091895*Avol0*Cj*Rsh**3*fp*s**2 + 1.0*Avol0*Rf*Rsh*fp**2 + 0.159154943091895*Avol0*Rf*Rsh*fp*s + 1.0*Avol0*Rsh**2*fp**2 + 0.159154943091895*Avol0*Rsh**2*fp*s + 1.0*Cf**3*Cj*Rf**3*Rsh**3*fp**2*s**4 + 0.318309886183791*Cf**3*Cj*Rf**3*Rsh**3*fp*s**5 + 0.0253302959105844*Cf**3*Cj*Rf**3*Rsh**3*s**6 + 1.0*Cf**3*Rf**3*Rsh**2*fp**2*s**3 + 0.318309886183791*Cf**3*Rf**3*Rsh**2*fp*s**4 + 0.0253302959105844*Cf**3*Rf**3*Rsh**2*s**5 + 2.0*Cf**2*Cj**2*Rf**3*Rsh**3*fp**2*s**4 + 0.636619772367581*Cf**2*Cj**2*Rf**3*Rsh**3*fp*s**5 + 0.0506605918211689*Cf**2*Cj**2*Rf**3*Rsh**3*s**6 + 4.0*Cf**2*Cj*Rf**3*Rsh**2*fp**2*s**3 + 1.27323954473516*Cf**2*Cj*Rf**3*Rsh**2*fp*s**4 + 0.101321183642338*Cf**2*Cj*Rf**3*Rsh**2*s**5 + 3.0*Cf**2*Cj*Rf**2*Rsh**3*fp**2*s**3 + 0.954929658551372*Cf**2*Cj*Rf**2*Rsh**3*fp*s**4 + 0.0759908877317533*Cf**2*Cj*Rf**2*Rsh**3*s**5 + 2.0*Cf**2*Rf**3*Rsh*fp**2*s**2 + 0.636619772367581*Cf**2*Rf**3*Rsh*fp*s**3 + 0.0506605918211689*Cf**2*Rf**3*Rsh*s**4 + 3.0*Cf**2*Rf**2*Rsh**2*fp**2*s**2 + 0.954929658551372*Cf**2*Rf**2*Rsh**2*fp*s**3 + 0.0759908877317533*Cf**2*Rf**2*Rsh**2*s**4 + 1.0*Cf*Cj**3*Rf**3*Rsh**3*fp**2*s**4 + 0.318309886183791*Cf*Cj**3*Rf**3*Rsh**3*fp*s**5 + 0.0253302959105844*Cf*Cj**3*Rf**3*Rsh**3*s**6 + 3.0*Cf*Cj**2*Rf**3*Rsh**2*fp**2*s**3 + 0.954929658551372*Cf*Cj**2*Rf**3*Rsh**2*fp*s**4 + 0.0759908877317533*Cf*Cj**2*Rf**3*Rsh**2*s**5 + 4.0*Cf*Cj**2*Rf**2*Rsh**3*fp**2*s**3 + 1.27323954473516*Cf*Cj**2*Rf**2*Rsh**3*fp*s**4 + 0.101321183642338*Cf*Cj**2*Rf**2*Rsh**3*s**5 + 3.0*Cf*Cj*Rf**3*Rsh*fp**2*s**2 + 0.954929658551372*Cf*Cj*Rf**3*Rsh*fp*s**3 + 0.0759908877317533*Cf*Cj*Rf**3*Rsh*s**4 + 8.0*Cf*Cj*Rf**2*Rsh**2*fp**2*s**2 + 2.54647908947033*Cf*Cj*Rf**2*Rsh**2*fp*s**3 + 0.202642367284676*Cf*Cj*Rf**2*Rsh**2*s**4 + 3.0*Cf*Cj*Rf*Rsh**3*fp**2*s**2 + 0.954929658551372*Cf*Cj*Rf*Rsh**3*fp*s**3 + 0.0759908877317533*Cf*Cj*Rf*Rsh**3*s**4 + 1.0*Cf*Rf**3*fp**2*s + 0.318309886183791*Cf*Rf**3*fp*s**2 + 0.0253302959105844*Cf*Rf**3*s**3 + 4.0*Cf*Rf**2*Rsh*fp**2*s + 1.27323954473516*Cf*Rf**2*Rsh*fp*s**2 + 0.101321183642338*Cf*Rf**2*Rsh*s**3 + 3.0*Cf*Rf*Rsh**2*fp**2*s + 0.954929658551372*Cf*Rf*Rsh**2*fp*s**2 + 0.0759908877317533*Cf*Rf*Rsh**2*s**3 + 1.0*Cj**3*Rf**2*Rsh**3*fp**2*s**3 + 0.318309886183791*Cj**3*Rf**2*Rsh**3*fp*s**4 + 0.0253302959105844*Cj**3*Rf**2*Rsh**3*s**5 + 3.0*Cj**2*Rf**2*Rsh**2*fp**2*s**2 + 0.954929658551372*Cj**2*Rf**2*Rsh**2*fp*s**3 + 0.0759908877317533*Cj**2*Rf**2*Rsh**2*s**4 + 2.0*Cj**2*Rf*Rsh**3*fp**2*s**2 + 0.636619772367581*Cj**2*Rf*Rsh**3*fp*s**3 + 0.0506605918211689*Cj**2*Rf*Rsh**3*s**4 + 3.0*Cj*Rf**2*Rsh*fp**2*s + 0.954929658551372*Cj*Rf**2*Rsh*fp*s**2 + 0.0759908877317533*Cj*Rf**2*Rsh*s**3 + 4.0*Cj*Rf*Rsh**2*fp**2*s + 1.27323954473516*Cj*Rf*Rsh**2*fp*s**2 + 0.101321183642338*Cj*Rf*Rsh**2*s**3 + 1.0*Cj*Rsh**3*fp**2*s + 0.318309886183791*Cj*Rsh**3*fp*s**2 + 0.0253302959105844*Cj*Rsh**3*s**3 + 1.0*Rf**2*fp**2 + 0.318309886183791*Rf**2*fp*s + 0.0253302959105844*Rf**2*s**2 + 2.0*Rf*Rsh*fp**2 + 0.636619772367581*Rf*Rsh*fp*s + 0.0506605918211689*Rf*Rsh*s**2 + 1.0*Rsh**2*fp**2 + 0.318309886183791*Rsh**2*fp*s + 0.0253302959105844*Rsh**2*s**2)
There is a difference between the maxima code and the python one: const 'pi' is kept symbolic in the first case, and approximated to a floating-point value in the second. Replacing np.pi with pi solves the problem, anyway it is weird how sympy tries to simplify the expression when pi is numeric.
Error , Infeasible No value for uninitialized NumericValue object
I'm trying to optmize a problem of clients/facility allocation and I'm using pyomo to do so. I have the following problem that appear and cannot solve it even if I initialize all the values of Model.z to 0; the problems is still infeasible from __future__ import division import pyomo.environ as pyo #from pyomo.environ import * from pyomo.opt import SolverFactory import sys import numpy as np import sys import os from time import perf_counter from pulp import * from pyomo.util.infeasible import log_infeasible_constraints #print(sys.path) opt = pyo.SolverFactory('glpk') opt.options['threads'] =4 #import instance model = pyo.ConcreteModel() # n is the number of facility related to J # m is the number of clients related to I # t is the number of periods relatdd to T # H is the maximum number of clients that can be served [m,n,t,H] = np.genfromtxt(fname = r'./Instances/data-100-10-4-3-0.txt', dtype = None, max_rows = 1) f_values = np.genfromtxt(fname = r'./Instances/data-100-10-4-3-0.txt', dtype = None, max_rows = 4,skip_header=1) c_values = np.genfromtxt(fname = r'./Instances/data-100-10-4-3-0.txt', dtype = None, skip_footer = 1,skip_header=5) p_values = np.genfromtxt(fname = r'./Instances/data-100-10-4-3-0.txt', dtype = None, skip_header=405) model.J = pyo.Set(initialize=[int(i)+1 for i in range(n)]) model.T= pyo.Set(initialize=[int(i)+1 for i in range(t)]) model.T.pprint() model.I = pyo.Set(initialize=[int(i)+1 for i in range(m)]) model.H = pyo.Set(initialize=[int(i)+1 for i in range(H)]) # Generation of Subsets of all clients client_list = [int(i)+1 for i in range(100)] list_H = [int(i)+1 for i in range(H)] possible_groups_of_clients=[] for i in list_H: possible_groups_of_clients += [list(elem) for elem in itertools.combinations(client_list,i)] possible_groups_of_clients = possible_groups_of_clients[0:5] #Only select the first 5 subsets model.K = pyo.Set(initialize=[int(i)+1 for i in range(len(possible_groups_of_clients))]) p_val = np.zeros((len(model.K),len(model.J),len(model.T))) for t in model.T: t=t-1 #Pyomo starts at 1 for j in model.J: j=j-1 count = 0 for k in possible_groups_of_clients: #k=k+1 c_sum=0; for p in k: if t==0: c_sum = c_sum +c_values[p][j] elif t==1: c_sum = c_sum +c_values[p+100][j] elif t==2: c_sum = c_sum +c_values[p+200][j] elif t==3: c_sum = c_sum +c_values[p+300][j] #print(f_values[t][j]) p_val[count][j][t] = f_values[t][j]+ c_sum count=count+1 model.p_val = pyo.Param(model.K,model.J,model.T, initialize = lambda model,k,j,t: p_val[k-1][j-1][t-1]) #Matrice Aik A = [[0 for k in range(len(possible_groups_of_clients))] for i in range(100)] #model.p_val = pyo.Param(model.T,model.J,model.K, initialize = lambda model,t,j,k: A[t-1][j-1][k-1]) model.A = pyo.Param(model.I, model.K, mutable= True,initialize= lambda model,i,k: A[i-1][k-1]) count=1 for i in possible_groups_of_clients: for k in range(100): k=k+1 #print(k) if k in i: model.A[k,count]=1 else: model.A[k,count]=0 count=count+1 model.z = pyo.Var(model.K,model.J,model.T,initialize= 0,within=pyo.NonNegativeReals,bounds=(0,1)) a=range(len(possible_groups_of_clients)) print(p_values) # Minization of objective functions # Constraint unique client model.uniq_client = pyo.Constraint( model.I, rule=lambda model, i: sum(model.A[i,k]*model.z[k,j,t] for t in model.T for j in model.J for k in model.K) == 1 ) model.unique_service_groupclients = pyo.Constraint( model.J, model.T, rule=lambda model,j,t: sum(model.z[k,j,t] for k in model.K)<=1 ) model.min_factory_perperiod = pyo.Constraint( model.T, rule=lambda model, t: sum(model.z[k,j,t] for j in model.J for k in model.K )>=p_values[t-1] ) model.obj = pyo.Objective(rule= lambda model:sum(model.p_val[k,j,t]*model.z[k,j,t] for t in model.T for j in model.J for k in model.K ), sense= pyo.minimize) model.pprint() Constraint Group Client sol = pyo.SolverFactory('glpk',).solve(model).write() log_infeasible_constraints(model) # ========================================================== # = Solver Results = # ========================================================== # ---------------------------------------------------------- # Problem Information # ---------------------------------------------------------- Problem: - Name: unknown Lower bound: -inf Upper bound: inf Number of objectives: 1 Number of constraints: 145 Number of variables: 201 Number of nonzeros: 601 Sense: minimize # ---------------------------------------------------------- # Solver Information # ---------------------------------------------------------- Solver: - Status: ok Termination condition: infeasible Statistics: Branch and bound: Number of bounded subproblems: 0 Number of created subproblems: 0 Error rc: 0 Time: 0.008042335510253906 ERROR: evaluating object as numeric value: z[1,1,1] (object: <class 'pyomo.core.base.var._GeneralVarData'>) No value for uninitialized NumericValue object z[1,1,1] ERROR: evaluating object as numeric value: 1.0 - (A[1,1]*z[1,1,1] + A[1,2]*z[2,1,1] + A[1,3]*z[3,1,1] + A[1,4]*z[4,1,1] + A[1,5]*z[5,1,1] + A[1,1]*z[1,2,1] + A[1,2]*z[2,2,1] + A[1,3]*z[3,2,1] + A[1,4]*z[4,2,1] + A[1,5]*z[5,2,1] + A[1,1]*z[1,3,1] + A[1,2]*z[2,3,1] + A[1,3]*z[3,3,1] + A[1,4]*z[4,3,1] + A[1,5]*z[5,3,1] + A[1,1]*z[1,4,1] + A[1,2]*z[2,4,1] + A[1,3]*z[3,4,1] + A[1,4]*z[4,4,1] + A[1,5]*z[5,4,1] + A[1,1]*z[1,5,1] + A[1,2]*z[2,5,1] + A[1,3]*z[3,5,1] + A[1,4]*z[4,5,1] + A[1,5]*z[5,5,1] + A[1,1]*z[1,6,1] + A[1,2]*z[2,6,1] + A[1,3]*z[3,6,1] + A[1,4]*z[4,6,1] + A[1,5]*z[5,6,1] + A[1,1]*z[1,7,1] + A[1,2]*z[2,7,1] + A[1,3]*z[3,7,1] + A[1,4]*z[4,7,1] + A[1,5]*z[5,7,1] + A[1,1]*z[1,8,1] + A[1,2]*z[2,8,1] + A[1,3]*z[3,8,1] + A[1,4]*z[4,8,1] + A[1,5]*z[5,8,1] + A[1,1]*z[1,9,1] + A[1,2]*z[2,9,1] + A[1,3]*z[3,9,1] + A[1,4]*z[4,9,1] + A[1,5]*z[5,9,1] + A[1,1]*z[1,10,1] + A[1,2]*z[2,10,1] + A[1,3]*z[3,10,1] + A[1,4]*z[4,10,1] + A[1,5]*z[5,10,1] + A[1,1]*z[1,1,2] + A[1,2]*z[2,1,2] + A[1,3]*z[3,1,2] + A[1,4]*z[4,1,2] + A[1,5]*z[5,1,2] + A[1,1]*z[1,2,2] + A[1,2]*z[2,2,2] + A[1,3]*z[3,2,2] + A[1,4]*z[4,2,2] + A[1,5]*z[5,2,2] + A[1,1]*z[1,3,2] + A[1,2]*z[2,3,2] + A[1,3]*z[3,3,2] + A[1,4]*z[4,3,2] + A[1,5]*z[5,3,2] + A[1,1]*z[1,4,2] + A[1,2]*z[2,4,2] + A[1,3]*z[3,4,2] + A[1,4]*z[4,4,2] + A[1,5]*z[5,4,2] + A[1,1]*z[1,5,2] + A[1,2]*z[2,5,2] + A[1,3]*z[3,5,2] + A[1,4]*z[4,5,2] + A[1,5]*z[5,5,2] + A[1,1]*z[1,6,2] + A[1,2]*z[2,6,2] + A[1,3]*z[3,6,2] + A[1,4]*z[4,6,2] + A[1,5]*z[5,6,2] + A[1,1]*z[1,7,2] + A[1,2]*z[2,7,2] + A[1,3]*z[3,7,2] + A[1,4]*z[4,7,2] + A[1,5]*z[5,7,2] + A[1,1]*z[1,8,2] + A[1,2]*z[2,8,2] + A[1,3]*z[3,8,2] + A[1,4]*z[4,8,2] + A[1,5]*z[5,8,2] + A[1,1]*z[1,9,2] + A[1,2]*z[2,9,2] + A[1,3]*z[3,9,2] + A[1,4]*z[4,9,2] + A[1,5]*z[5,9,2] + A[1,1]*z[1,10,2] + A[1,2]*z[2,10,2] + A[1,3]*z[3,10,2] + A[1,4]*z[4,10,2] + A[1,5]*z[5,10,2] + A[1,1]*z[1,1,3] + A[1,2]*z[2,1,3] + A[1,3]*z[3,1,3] + A[1,4]*z[4,1,3] + A[1,5]*z[5,1,3] + A[1,1]*z[1,2,3] + A[1,2]*z[2,2,3] + A[1,3]*z[3,2,3] + A[1,4]*z[4,2,3] + A[1,5]*z[5,2,3] + A[1,1]*z[1,3,3] + A[1,2]*z[2,3,3] + A[1,3]*z[3,3,3] + A[1,4]*z[4,3,3] + A[1,5]*z[5,3,3] + A[1,1]*z[1,4,3] + A[1,2]*z[2,4,3] + A[1,3]*z[3,4,3] + A[1,4]*z[4,4,3] + A[1,5]*z[5,4,3] + A[1,1]*z[1,5,3] + A[1,2]*z[2,5,3] + A[1,3]*z[3,5,3] + A[1,4]*z[4,5,3] + A[1,5]*z[5,5,3] + A[1,1]*z[1,6,3] + A[1,2]*z[2,6,3] + A[1,3]*z[3,6,3] + A[1,4]*z[4,6,3] + A[1,5]*z[5,6,3] + A[1,1]*z[1,7,3] + A[1,2]*z[2,7,3] + A[1,3]*z[3,7,3] + A[1,4]*z[4,7,3] + A[1,5]*z[5,7,3] + A[1,1]*z[1,8,3] + A[1,2]*z[2,8,3] + A[1,3]*z[3,8,3] + A[1,4]*z[4,8,3] + A[1,5]*z[5,8,3] + A[1,1]*z[1,9,3] + A[1,2]*z[2,9,3] + A[1,3]*z[3,9,3] + A[1,4]*z[4,9,3] + A[1,5]*z[5,9,3] + A[1,1]*z[1,10,3] + A[1,2]*z[2,10,3] + A[1,3]*z[3,10,3] + A[1,4]*z[4,10,3] + A[1,5]*z[5,10,3] + A[1,1]*z[1,1,4] + A[1,2]*z[2,1,4] + A[1,3]*z[3,1,4] + A[1,4]*z[4,1,4] + A[1,5]*z[5,1,4] + A[1,1]*z[1,2,4] + A[1,2]*z[2,2,4] + A[1,3]*z[3,2,4] + A[1,4]*z[4,2,4] + A[1,5]*z[5,2,4] + A[1,1]*z[1,3,4] + A[1,2]*z[2,3,4] + A[1,3]*z[3,3,4] + A[1,4]*z[4,3,4] + A[1,5]*z[5,3,4] + A[1,1]*z[1,4,4] + A[1,2]*z[2,4,4] + A[1,3]*z[3,4,4] + A[1,4]*z[4,4,4] + A[1,5]*z[5,4,4] + A[1,1]*z[1,5,4] + A[1,2]*z[2,5,4] + A[1,3]*z[3,5,4] + A[1,4]*z[4,5,4] + A[1,5]*z[5,5,4] + A[1,1]*z[1,6,4] + A[1,2]*z[2,6,4] + A[1,3]*z[3,6,4] + A[1,4]*z[4,6,4] + A[1,5]*z[5,6,4] + A[1,1]*z[1,7,4] + A[1,2]*z[2,7,4] + A[1,3]*z[3,7,4] + A[1,4]*z[4,7,4] + A[1,5]*z[5,7,4] + A[1,1]*z[1,8,4] + A[1,2]*z[2,8,4] + A[1,3]*z[3,8,4] + A[1,4]*z[4,8,4] + A[1,5]*z[5,8,4] + A[1,1]*z[1,9,4] + A[1,2]*z[2,9,4] + A[1,3]*z[3,9,4] + A[1,4]*z[4,9,4] + A[1,5]*z[5,9,4] + A[1,1]*z[1,10,4] + A[1,2]*z[2,10,4] + A[1,3]*z[3,10,4] + A[1,4]*z[4,10,4] + A[1,5]*z[5,10,4]) (object: <class 'pyomo.core.expr.numeric_expr.SumExpression'>) No value for uninitialized NumericValue object z[1,1,1] Traceback (most recent call last): File "main.py", line 246, in <module> log_infeasible_constraints(model) File "/home/john/.local/lib/python3.6/site-packages/pyomo /util/infeasible.py", line 25, in log_infeasible_constraints if constr.equality and fabs(value(constr.lower - constr.body)) >= tol: File "/home/john/.local/lib/python3.6/site-packages/pyomo/core/expr/numvalue.py", line 226, in value tmp = obj(exception=True) File "/home/john/.local/lib/python3.6/site-packages/pyomo/core/expr/numeric_expr.py", line 222, in __call__ return evaluate_expression(self, exception) File "/home/john/.local/lib/python3.6/site-packages/pyomo/core/expr/visitor.py", line 973, in evaluate_expression return visitor.dfs_postorder_stack(exp) File "/home/john/.local/lib/python3.6/site-packages/pyomo/core/expr/visitor.py", line 518, in dfs_postorder_stack flag, value = self.visiting_potential_leaf(_sub) File "/home/john/.local/lib/python3.6/site-packages/pyomo/core/expr/visitor.py", line 893, in visiting_potential_leaf return True, value(node) File "/home/john/.local/lib/python3.6/site-packages/pyomo/core/expr/numvalue.py", line 230, in value % (obj.name,)) ValueError: No value for uninitialized NumericValue object z[1,1,1] I got this error whatever I try and I don't understand why Z should be initialized as it is the variable I'm trying to minimize
Naming LDA topics in Python
I am new to python and trying to implement topic modelling. I am successful in implementing LDA in pything using gensim , but I am not able to give any label/name to these topics. How do we name these topics? please help out with the best way to implement in python. My LDA output is somewhat like this(please let me know if you need the code) :- 0.024*research + 0.021*students + 0.019*conference + 0.019*chi + 0.017*field + 0.014*work + 0.013*student + 0.013*hci + 0.013*group + 0.013*researchers 0.047*research + 0.034*students + 0.020*ustars + 0.018*underrepresented + 0.017*participants + 0.012*researchers + 0.012*mathematics + 0.012*graduate + 0.012*mathematical + 0.012*conference 0.027*students + 0.026*research + 0.018*conference + 0.017*field + 0.015*new + 0.014*participants + 0.013*chi + 0.012*robotics + 0.010*researchers + 0.010*student 0.023*students + 0.019*robotics + 0.018*conference + 0.017*international + 0.016*interact + 0.016*new + 0.016*ph.d. + 0.016*meet + 0.016*ieee + 0.015*u.s. 0.033*research + 0.030*flow + 0.028*field + 0.023*visualization + 0.020*challenges + 0.017*students + 0.015*project + 0.013*shape + 0.013*visual + 0.012*data 0.044*research + 0.020*mathematics + 0.017*program + 0.014*june + 0.014*conference + 0.014*- + 0.013*mathematicians + 0.013*conferences + 0.011*field + 0.011*mrc 0.023*research + 0.021*students + 0.015*field + 0.014*hovering + 0.014*mechanisms + 0.014*dpiv + 0.013*aerodynamic + 0.012*unsteady + 0.012*conference + 0.012*hummingbirds 0.031*research + 0.018*mathematics + 0.016*program + 0.014*flow + 0.014*mathematicians + 0.012*conferences + 0.011*field + 0.011*june + 0.010*visualization + 0.010*communities 0.028*students + 0.028*research + 0.018*ustars + 0.018*mathematics + 0.015*underrepresented + 0.010*program + 0.010*encouraging + 0.010*'', + 0.010*participants + 0.010*conference 0.049*research + 0.021*conference + 0.021*program + 0.020*mathematics + 0.014*mathematicians + 0.013*field + 0.013*- + 0.011*conferences + 0.010*areas
Labeling topics is completely distinct from topic modeling. Here's an article that describes using a keyword extraction technique (KERA) to apply meaningful labels to topics: http://arxiv.org/abs/1308.2359