Skip to content

Getting started

artofscience edited this page Sep 3, 2021 · 6 revisions

Let's get started.

Build your own problem

The abstract "Problem" class can be used to set up an optimization problem. Key methods are the calculation of response values g(x) and accompanying sensitivities dg(x) and ddg(x).

Consider a system of n springs in series, each with stiffness x_i. We aim to find the stiffest combination of spring stiffness with a limited amount of material available.

Spring: min(x) -1/sum(1/x_i) s.t. sum(x_i)/(n*v) - 1 <= 0 0 < x_i < 1 for all i = 1,...,n

An example implementation is

class Spring(Problem):

def __init(self, x0=None, v = 0.5):
if x0 is not None:
self.x0 = x0
else:
self.x0 = np.random(10,1)

self.n = np.size(x0)
self.m = 1
self.x_min = np.zeros(self.n,1)
self.x_max = np.ones(self.n,1)

self.v = v

def g(self, x): 
return [-1/(np.sum(1/x)), sum(x)/(self.n*self.v) - 1]

def dg(self, x): return

def ddg(self, x): return

This problem is obviously very simple, and there would be no need to use SAO to solve this problem. However, it serves the purpose for now. Note the problem may be very complex, such as the topology optimization problems that can be found in LINK.

Using wrappers

Clone this wiki locally