examples

command
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2017 License: BSD-3-Clause Imports: 5 Imported by: 0

README

Goga – examples

Summary

  1. Very simple problem
  2. Constrained one-objective problems
  3. Unconstrained two-objective problems
  4. Constrained two-objective problems
  5. Constrained and unconstrained three-objective problems
  6. Unconstrained many-objectives problems
  7. Truss shape and topology optimisation
  8. Economic emission load dispatch

0 Very simple problem

Goga can use two types of objective functions:

(A) the higher-level one: MinProb_t which takes the vector of random variables x and returns the objectives values in f. It may also return the inequality constraints in g and the equality constraints in h. It also accepts integer random variables in y

(B) the lower-level one: ObjFunc_t which takes the pointer to a candidate solution object (Solution) and fills the Ova array in this object with the objective values. In this method the vector of random variables x is stored as Flt

Both functions take the cpu number as input if that's necessary (rarely)

The functions definitions of each case are shown below

ObjFunc_t defines the objective fuction type ObjFunc_t func(sol *Solution, cpu int)

MinProb_t defines objective functon for specialised minimisation problem type MinProb_t func(f, g, h, x []float64, y []int, cpu int)

// case A: finding the minimum of 2.0 + (1+x)²
func fcnA(f, g, h, x []float64, y []int, cpu int) {
	f[0] = 2.0 + (1.0+x[0])*(1.0+x[0])
}

// case A: finding the minimum of 2.0 + (1+x)² (same function, but different function call)
func fcnB(sol *goga.Solution, cpu int) {
	x := sol.Flt
	sol.Ova[0] = 2.0 + (1.0+x[0])*(1.0+x[0])
}

// main function
func main() {

	// problem definition
	nf := 1 // number of objective functions
	ng := 0 // number of inequality constraints
	nh := 0 // number of equality constraints

	// the solver (optimiser)
	var opt goga.Optimiser
	opt.Default()              // must call this to set default constants
	opt.FltMin = []float64{-2} // must set minimum
	opt.FltMax = []float64{2}  // must set maximum

	// initialise the solver
	useMethodA := false
	if useMethodA {
		opt.Init(goga.GenTrialSolutions, nil, fcnA, nf, ng, nh)
	} else {
		opt.Init(goga.GenTrialSolutions, fcnB, nil, nf, ng, nh)
	}

	// solve problem
	opt.Solve()

	// print results
	xBest := opt.Solutions[0].Flt[0]
	fBest := 2.0 + (1.0+xBest)*(1.0+xBest)
	io.Pf("xBest    = %v\n", xBest)
	io.Pf("f(xBest) = %v\n", fBest)

	// plotting
	fvec := []float64{0} // temporary vector to use with fcnA
	xvec := []float64{0} // temporary vector to use with fcnA
	X := utl.LinSpace(-2, 2, 101)
	F := utl.GetMapped(X, func(x float64) float64 {
		xvec[0] = x
		fcnA(fvec, nil, nil, xvec, nil, 0)
		return fvec[0]
	})
	plt.PlotOne(xBest, fBest, &plt.A{C: "r", M: "o", Ms: 20, NoClip: true})
	plt.Plot(X, F, nil)
	plt.Gll("$x$", "$f$", nil)
	plt.Save("/tmp/goga", "simple01")
}

Source code: simple/simple01.go

Output of simple01.go

1 Constrained one-objective problems

Source code: one-obj.go

2 Unconstrained two-objective problems

Source code: two-obj.go

3 Constrained two-objective problems

Source code: two-obj-ct.go

4 Constrained and unconstrained three-objective problems

Source code: three-obj.go

5 Unconstrained many-objectives problems

Source code: many-obj.go

6 Truss shape and topology optimisation

Source code: topology.go and femsim.go

7 Economic emission load dispatch

Source code: ecoemission.go and generators.go

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
mulobj-cec09
mulobj-wfg
wfg
+build ignore
+build ignore

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL