예제 #1
0
 def __init__(self, *args, **kwargs):
     super(Response, self).__init__(*args, **kwargs)
     self._pseudo = None
     self._pseudo = PseudoComponent(self.scope,
                                    self,
                                    pseudo_type='objective')
     self.pcomp_name = self._pseudo.name
class Objective(ConnectedExprEvaluator):
    def __init__(self, *args, **kwargs):
        super(Objective, self).__init__(*args, **kwargs)
        self._pseudo = None
        unresolved_vars = self.get_unresolved()
        if unresolved_vars:
            msg = "Can't add objective '{0}' because of invalid variables {1}"
            raise ConnectedExprEvaluator._invalid_expression_error(unresolved_vars, self.text, msg)

        self._pseudo = PseudoComponent(self.scope, self, pseudo_type='objective')
        self.pcomp_name = self._pseudo.name

    def activate(self, driver):
        """Make this constraint active by creating the appropriate
        connections in the dependency graph.
        """
        self._pseudo.activate(self.scope, driver)

    def deactivate(self):
        """Remove this objective from the dependency graph and remove
        its pseudocomp from the scoping object.
        """
        if self._pseudo is not None:
            scope = self.scope
            try:
                getattr(scope, self._pseudo.name)
            except AttributeError:
                pass
            else:
                scope.remove(self._pseudo.name)

    def evaluate(self, scope=None):
        """Use the value in the u vector if it exists instead of pulling
        the value from scope.
        """
        if self.pcomp_name:
            scope = self._get_updated_scope(scope)
            try:
                system = getattr(scope, self.pcomp_name)._system
                vname = self.pcomp_name + '.out0'
                if scope._var_meta[vname].get('scalar'):
                    return system.vec['u'][scope.name2collapsed[vname]][0]
                else:
                    return system.vec['u'][scope.name2collapsed[vname]]
            except (KeyError, AttributeError):
                pass

        return super(Objective, self).evaluate(scope)
예제 #3
0
class Response(ConnectedExprEvaluator):
    def __init__(self, *args, **kwargs):
        super(Response, self).__init__(*args, **kwargs)
        self._pseudo = None
        self._pseudo = PseudoComponent(self.scope,
                                       self,
                                       pseudo_type='objective')
        self.pcomp_name = self._pseudo.name

    def activate(self, driver):
        """Make this response active by creating the appropriate
        connections in the dependency graph.
        """
        self._pseudo.activate(self.scope, driver)

    def deactivate(self):
        """Remove this response from the dependency graph and remove
        its pseudocomp from the scoping object.
        """
        if self._pseudo is not None:
            scope = self.scope
            try:
                getattr(scope, self._pseudo.name)
            except AttributeError:
                pass
            else:
                scope.remove(self._pseudo.name)

    def evaluate(self, scope=None):
        """Use the value in the u vector if it exists instead of pulling
        the value from scope.
        """
        if self.pcomp_name:
            scope = self._get_updated_scope(scope)
            try:
                system = getattr(scope, self.pcomp_name)._system
                vname = self.pcomp_name + '.out0'
                if scope._var_meta[vname].get('scalar'):
                    return system.vec['u'][scope.name2collapsed[vname]][0]
                else:
                    return system.vec['u'][scope.name2collapsed[vname]]
            except (KeyError, AttributeError):
                pass

        return super(Response, self).evaluate(scope)
예제 #4
0
 def activate(self):
     """Make this constraint active by creating the appropriate
     connections in the dependency graph.
     """
     if self.pcomp_name is None:
         pseudo = PseudoComponent(self.scope, self, pseudo_type='objective')
         self.pcomp_name = pseudo.name
         self.scope.add(pseudo.name, pseudo)
     getattr(self.scope, self.pcomp_name).make_connections(self.scope)
class Response(ConnectedExprEvaluator):
    def __init__(self, *args, **kwargs):
        super(Response, self).__init__(*args, **kwargs)
        self._pseudo = None
        self._pseudo = PseudoComponent(self.scope, self, pseudo_type="objective")
        self.pcomp_name = self._pseudo.name

    def activate(self, driver):
        """Make this response active by creating the appropriate
        connections in the dependency graph.
        """
        self._pseudo.activate(self.scope, driver)

    def deactivate(self):
        """Remove this response from the dependency graph and remove
        its pseudocomp from the scoping object.
        """
        if self._pseudo is not None:
            scope = self.scope
            try:
                getattr(scope, self._pseudo.name)
            except AttributeError:
                pass
            else:
                scope.remove(self._pseudo.name)

    def evaluate(self, scope=None):
        """Use the value in the u vector if it exists instead of pulling
        the value from scope.
        """
        if self.pcomp_name:
            scope = self._get_updated_scope(scope)
            try:
                system = getattr(scope, self.pcomp_name)._system
                vname = self.pcomp_name + ".out0"
                if scope._var_meta[vname].get("scalar"):
                    return system.vec["u"][scope.name2collapsed[vname]][0]
                else:
                    return system.vec["u"][scope.name2collapsed[vname]]
            except (KeyError, AttributeError):
                pass

        return super(Response, self).evaluate(scope)
    def __init__(self, *args, **kwargs):
        super(Objective, self).__init__(*args, **kwargs)
        self._pseudo = None
        unresolved_vars = self.get_unresolved()
        if unresolved_vars:
            msg = "Can't add objective '{0}' because of invalid variables {1}"
            raise ConnectedExprEvaluator._invalid_expression_error(unresolved_vars, self.text, msg)

        self._pseudo = PseudoComponent(self.scope, self, pseudo_type='objective')
        self.pcomp_name = self._pseudo.name
 def __init__(self, *args, **kwargs):
     super(Response, self).__init__(*args, **kwargs)
     self._pseudo = None
     self._pseudo = PseudoComponent(self.scope, self, pseudo_type="objective")
     self.pcomp_name = self._pseudo.name