Example #1
0
    def all_constraints(self, x=None):
        """Returns both the inequality and equality constraint values for your function
    
            Assumptions:
            N/A
    
            Source:
            N/A
    
            Inputs:
            x                  [vector]
    
            Outputs:
            scaled_constraints [vector]
    
            Properties Used:
            None
        """

        self.evaluate(x)

        aliases = self.optimization_problem.aliases
        constraints = self.optimization_problem.constraints
        results = self.results

        constraint_values = help_fun.get_values(self, constraints, aliases)
        scaled_constraints = help_fun.scale_const_values(
            constraints, constraint_values)

        return scaled_constraints
Example #2
0
File: Nexus.py Project: michK/SUAVE
 def all_constraints(self,x = None):
     """Returns both the inequality and equality constraint values for your function
 
         Assumptions:
         N/A
 
         Source:
         N/A
 
         Inputs:
         x                  [vector]
 
         Outputs:
         scaled_constraints [vector]
 
         Properties Used:
         None
     """         
     
     self.evaluate(x)
     
     aliases     = self.optimization_problem.aliases
     constraints = self.optimization_problem.constraints
     results     = self.results
 
     constraint_values  = help_fun.get_values(self,constraints,aliases) 
     scaled_constraints = help_fun.scale_const_values(constraints,constraint_values)
 
     return scaled_constraints     
Example #3
0
 def all_constraints(self,x = None):
     
     self.evaluate(x)
     
     aliases     = self.optimization_problem.aliases
     constraints = self.optimization_problem.constraints
     results     = self.results
 
     constraint_values = help_fun.get_values(self,constraints,aliases) 
     scaled_constraints = help_fun.scale_const_values(constraints,constraint_values)
 
     return scaled_constraints     
Example #4
0
 def all_constraints(self,x = None):
     
     self.evaluate(x)
     
     aliases     = self.optimization_problem.aliases
     constraints = self.optimization_problem.constraints
     results     = self.results
 
     constraint_values = help_fun.get_values(self,constraints,aliases) 
     scaled_constraints = help_fun.scale_const_values(constraints,constraint_values)
 
     return scaled_constraints     
Example #5
0
    def inequality_constraint(self, x=None):
        """Retrieve the inequality constraint values for your function
    
            Assumptions:
            N/A
    
            Source:
            N/A
    
            Inputs:
            x                  [vector]
    
            Outputs:
            scaled_constraints [vector]
    
            Properties Used:
            None
            """

        self.evaluate(x)

        aliases = self.optimization_problem.aliases
        constraints = self.optimization_problem.constraints
        results = self.results

        # Setup constraints
        indices = []
        for ii in xrange(0, len(constraints)):
            if constraints[ii][1] == ('='):
                indices.append(ii)
        iqconstraints = np.delete(constraints, indices, axis=0)

        if iqconstraints == []:
            scaled_constraints = []
        else:
            constraint_values = help_fun.get_values(self, iqconstraints,
                                                    aliases)
            constraint_values[iqconstraints[:, 1] == '<'] = -constraint_values[
                iqconstraints[:, 1] == '<']
            bnd_constraints = constraint_values - help_fun.scale_const_bnds(
                iqconstraints)
            scaled_constraints = help_fun.scale_const_values(
                iqconstraints, constraint_values)

        return scaled_constraints
def write_optimization_outputs(nexus, filename):

    #unpack optimization problem values
    objective = nexus.optimization_problem.objective
    aliases = nexus.optimization_problem.aliases
    constraints = nexus.optimization_problem.constraints

    #inputs
    unscaled_inputs = nexus.optimization_problem.inputs[:,
                                                        1]  #use optimization problem inputs here
    input_scaling = nexus.optimization_problem.inputs[:, 3]
    scaled_inputs = unscaled_inputs / input_scaling

    #objective
    objective_value = get_values(nexus, objective, aliases)
    scaled_objective = scale_obj_values(objective, objective_value)

    #constraints
    constraint_values = get_values(nexus, constraints, aliases)
    scaled_constraints = scale_const_values(constraints, constraint_values)

    problem_inputs = []
    problem_constraints = []
    for value in scaled_inputs:
        problem_inputs.append(
            value)  #writing to file is easier when you use list
    for value in scaled_constraints:
        problem_constraints.append(value)

    file = open(filename, 'ab')
    file.write('iteration = ')
    file.write(str(nexus.total_number_of_iterations))
    file.write(' , ')
    file.write('objective = ')
    file.write(str(scaled_objective[0]))
    file.write(', inputs = ')
    file.write(str(problem_inputs))
    file.write(', constraints = ')
    file.write(str(problem_constraints))

    file.write('\n')
    file.close()

    return
Example #7
0
File: Nexus.py Project: michK/SUAVE
    def equality_constraint(self,x = None):
        """Retrieve the equality constraint values for your function
    
            Assumptions:
            N/A
    
            Source:
            N/A
    
            Inputs:
            x                  [vector]
    
            Outputs:
            scaled_constraints [vector]
    
            Properties Used:
            None
        """         
    
        self.evaluate(x)

        aliases     = self.optimization_problem.aliases
        constraints = self.optimization_problem.constraints
        results     = self.results
        
        # Setup constraints  
        indices = []
        for ii in xrange(0,len(constraints)):
            if constraints[ii][1]=='>':
                indices.append(ii)
            elif constraints[ii][1]=='<':
                indices.append(ii)
        eqconstraints = np.delete(constraints,indices,axis=0)
    
        if eqconstraints == []:
            scaled_constraints = []
        else:
            constraint_values = help_fun.get_values(self,eqconstraints,aliases) - help_fun.scale_const_bnds(eqconstraints)
            scaled_constraints = help_fun.scale_const_values(eqconstraints,constraint_values)

        return scaled_constraints   
Example #8
0
    def equality_constraint(self,x = None):
        
        self.evaluate(x)

        aliases     = self.optimization_problem.aliases
        constraints = self.optimization_problem.constraints
        results     = self.results
        
        # Setup constraints  
        indices = []
        for ii in xrange(0,len(constraints)):
            if constraints[ii][1]=='>':
                indices.append(ii)
            elif constraints[ii][1]=='<':
                indices.append(ii)
        eqconstraints = np.delete(constraints,indices,axis=0)
    
        if eqconstraints == []:
            scaled_constraints = []
        else:
            constraint_values = help_fun.get_values(self,eqconstraints,aliases) - help_fun.scale_const_bnds(eqconstraints)
            scaled_constraints = help_fun.scale_const_values(eqconstraints,constraint_values)

        return scaled_constraints   
Example #9
0
    def equality_constraint(self,x = None):
        
        self.evaluate(x)

        aliases     = self.optimization_problem.aliases
        constraints = self.optimization_problem.constraints
        results     = self.results
        
        # Setup constraints  
        indices = []
        for ii in xrange(0,len(constraints)):
            if constraints[ii][1]=='>':
                indices.append(ii)
            elif constraints[ii][1]=='<':
                indices.append(ii)
        eqconstraints = np.delete(constraints,indices,axis=0)
    
        if eqconstraints == []:
            scaled_constraints = []
        else:
            constraint_values = help_fun.get_values(self,eqconstraints,aliases) - help_fun.scale_const_bnds(eqconstraints)
            scaled_constraints = help_fun.scale_const_values(eqconstraints,constraint_values)

        return scaled_constraints   
Example #10
0
def write_optimization_outputs(nexus, filename):
    """ Writes the optimization outputs to a file

    Assumptions:
    N/A

    Source:
    N/A

    Inputs:
    nexus            [nexus()]
    filename         [str]

    Outputs:
    N/A

    Properties Used:
    N/A
    """       
 
    #unpack optimization problem values
    objective          = nexus.optimization_problem.objective
    aliases            = nexus.optimization_problem.aliases
    constraints        = nexus.optimization_problem.constraints
    
    #inputs
    unscaled_inputs    = nexus.optimization_problem.inputs[:,1] #use optimization problem inputs here
    input_scaling      = nexus.optimization_problem.inputs[:,3]
    scaled_inputs      = unscaled_inputs/input_scaling
    
    #objective
    objective_value    = get_values(nexus,objective,aliases)
    scaled_objective   = scale_obj_values(objective , objective_value)
    
    #constraints
    constraint_values  = get_values(nexus,constraints,aliases) 
    scaled_constraints = scale_const_values(constraints,constraint_values)
    
    problem_inputs  = []
    problem_constraints = []
    for value in scaled_inputs:
        problem_inputs.append(value)  #writing to file is easier when you use list
    for value in scaled_constraints:
        problem_constraints.append(value)
    
    
    file=open(filename, 'ab')
    file.write('iteration = ')
    file.write(str(nexus.total_number_of_iterations))
    file.write(' , ')
    file.write('objective = ')
    file.write(str(scaled_objective[0]))
    file.write(', inputs = ')
    file.write(str(problem_inputs))
    file.write(', constraints = ')
    file.write(str(problem_constraints))
    
    file.write('\n') 
    file.close()
    
    return