Skip to content

Instantly share code, notes, and snippets.

@eponkratova
Created December 28, 2018 09:02
Show Gist options
  • Save eponkratova/0960017e7eebdf3a65989e71f7046d80 to your computer and use it in GitHub Desktop.
Save eponkratova/0960017e7eebdf3a65989e71f7046d80 to your computer and use it in GitHub Desktop.
initiating_gis
def __constraints(self, x, unit):
"""
Constraints for optimization for one unit
:param x: combined weights
:param unit: which production unit to compute
:return: array of constraints
"""
in_w, out_w, lambdas = x[:self.m], x[self.m:(self.m+self.r)], x[(self.m+self.r):] # unroll the weights
constr = [] # init the constraint array
# for each input, lambdas with inputs
for input in self.input_:
t = self.__target(x, unit)
lhs = np.dot(self.inputs[:, input], lambdas)
cons = t*self.inputs[unit, input] - lhs
constr.append(cons)
# for each output, lambdas with outputs
for output in self.output_:
lhs = np.dot(self.outputs[:, output], lambdas)
cons = lhs - self.outputs[unit, output]
constr.append(cons)
# for each unit
for u in self.unit_:
constr.append(lambdas[u])
return np.array(constr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment