Help to solve this problem
AnsweredI am looking for a way to solve the following problem(Balance equations)

I need to find pi that meets all the equations.(Stationary odds).
I have doubts when defining the objective function, because I don't know very well what I want to maximize or minimize. I just want to find a solution to the equations
This is what I have
from gurobipy import *
mod = Model('BalanceEquations')
lamda = 5.95
mu = 6
N = 4
K = 20
p = 0.4
ro = 1-(1-p)**N
#Variables
pi={}
for x in range(N+1):
for n in range(K+1):
pi[x,n]=mod.addVar(vtype="C",lb=0.0000001, name="pi_%s,%s" %(x,n))
#Constraints
for x in range(1,N):
for n in range(x,K):
mod.addConstr((lamda+mu)*pi[x,n] == lamda*pi[x,n-1] + mu*pi[x+1,n+1])
for n in range(1,N):
mod.addConstr(lamda*pi[0,n] == lamda*pi[0,n-1] + mu*pi[1,n+1] + mu*(1-ro)*pi[0,n+N])
for n in range(N,K+1-N):
mod.addConstr((lamda+mu)*pi[0,n] == lamda*pi[0,n-1] + mu*pi[1,n+1] + mu*(1-ro)*pi[0,n+N])
for n in range(1,K+1):
mod.addConstr((lamda+mu)*pi[N,n] == lamda*pi[N,n-1]+mu*ro*pi[0,n])
mod.addConstr(lamda*pi[0,0] == mu*pi[1,1]+mu*(1-ro)*pi[0,N])
mod.addConstr(quicksum(pi[x,n] for x in range(N+1) for n in range(K+1))==1)
#Here i have doubts
#The optimal result is always 1.0 only for a value pi [i, j], which doesn't work for me
mod.update()
mod.setObjective(quicksum(pi[i,j] for i in range(N+1) for j in range(K+1)),GRB.MAXIMIZE)
mod.optimize()
The optimal result is always 1.0 only for a value pi [i, j], which doesn't work for me. What I need are the values (probabilities) that the equations meet.
Thanks so much
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Dear Sebastian,
I have executed your code for \(N=2\) and \(K=3\) and noticed that the variable \(pi_{1,3}\) appears in your objective only. Thus, Gurobi simply sets this variable to the needed value in order to fulfill the \(=1\) equality and sets every other variable to its lower bound trivially fulfilling all other equality constraints.
I used the write function to investigate the model Gurobi is actually solving.
Please double check the formulas to make sure that every variable participates in the balance equations.I hope this could help you in resolving the issue.
Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments