def __init__(self, model, nsteps, *args, **kwargs): self.allow_isolated = True costs = kwargs.pop('costs', None) max_flows = kwargs.pop('max_flows', None) # TODO look at the application of Domains here. Having to use # Input/Output instead of BaseInput/BaseOutput because of a different # domain is required on the sub-nodes and they need to be connected self.sub_domain = Domain() self.input = Input(model, name='{} Input'.format(self.name), parent=self) self.output = Output(model, name='{} Output'.format(self.name), parent=self) self.sub_output = Output(model, name='{} Sub Output'.format(self.name), parent=self, domain=self.sub_domain) self.sub_output.connect(self.input) self.sublinks = [] for i in range(nsteps): sublink = Input(model, name='{} Sublink {}'.format(self.name, i), parent=self, domain=self.sub_domain) self.sublinks.append(sublink) sublink.connect(self.sub_output) self.output.connect(self.sublinks[-1]) super().__init__(model, *args, **kwargs) if costs is not None: self.costs = costs if max_flows is not None: self.max_flows = max_flows
def __init__(self, *args, **kwargs): self.allow_isolated = True costs = kwargs.pop('cost') max_flows = kwargs.pop('max_flow') super(PiecewiseLink, self).__init__(*args, **kwargs) if len(costs) != len(max_flows): raise ValueError("Piecewise max_flow and cost keywords must be the same length.") # TODO look at the application of Domains here. Having to use # Input/Output instead of BaseInput/BaseOutput because of a different # domain is required on the sub-nodes and they need to be connected self.sub_domain = Domain() self.input = Input(self.model, name='{} Input'.format(self.name), parent=self) self.output = Output(self.model, name='{} Output'.format(self.name), parent=self) self.sub_output = Output(self.model, name='{} Sub Output'.format(self.name), parent=self, domain=self.sub_domain) self.sub_output.connect(self.input) self.sublinks = [] for max_flow, cost in zip(max_flows, costs): self.sublinks.append(Input(self.model, name='{} Sublink {}'.format(self.name, len(self.sublinks)), cost=cost, max_flow=max_flow, parent=self, domain=self.sub_domain)) self.sublinks[-1].connect(self.sub_output) self.output.connect(self.sublinks[-1])