这是我要实现的功能。Non linear Equation to optimize。我如何退还总费用? 这是我的代码。
self._z = 1 self._qt_1 = 0 gurobi变量q_m_i_t也已创建,并且可以单独正常工作。
def __f(self,u): ## non linear function
"""
Equation for Deployment cost
Returns:
Piecewise Deployment cost
"""
return ((((u + self._z)*(np.log((u + self._z)/(self._qt_1 +self._z))))+ self._qt_1) - u)
def __deploymentcost_of_vnf(self): # VNF Deployment cost
"""
Calculates deployment cost of VNF which is the sum over product of
dost of deploying an instance of VNF in DataCenter and number of new
instances
Returns:
Deployment cost
"""
ptu = []
ptf = []
npts = 5
sigma = dict()
Deploymentcost = 0
gen10 = itertools.product(self._timeperiod,self._numberOfVNFs,
self._datacenters)
for t, m, i in gen10:
k = "q_" + str(m) + "_" + str(i) + "_" + str(t)
self.Vars[k] = self.model.getVarByName(
"q_" + str(m) + "_" + str(i) + "_" + str(t))
u = self.Vars[k]
sigma["sig_" + str(m) + "_" + str(i)] = 0.2
sigma1 = sigma["sig_" + str(m) + "_" + str(i)]
a = sigma1/self._n
piecewise = 0
for coo in range(npts):
ptu.append(0.25 * coo)
ptf.append(self.__f(ptu[coo]))
self.model.setPWLObj(u , ptu, ptf)
#piecewise = piecewise + ptf[coo]
#overall = piecewise*a # Scalling regularized answer
#Deploymentcost = Deploymentcost + overall
#print Deploymentcost
return Deploymentcost