コード例 #1
0
ファイル: individual.go プロジェクト: postfix/goga-1
// IndCompareDet compares individual 'A' with another one 'B'. Deterministic method
func IndCompareDet(A, B *Individual) (A_dominates, B_dominates bool) {
	var A_nviolations, B_nviolations int
	for i := 0; i < len(A.Oors); i++ {
		if A.Oors[i] > 0 {
			A_nviolations++
		}
		if B.Oors[i] > 0 {
			B_nviolations++
		}
	}
	if A_nviolations > 0 {
		if B_nviolations > 0 {
			if A_nviolations < B_nviolations {
				A_dominates = true
				return
			}
			if B_nviolations < A_nviolations {
				B_dominates = true
				return
			}
			A_dominates, B_dominates = utl.DblsParetoMin(A.Oors, B.Oors)
			if !A_dominates && !B_dominates {
				A_dominates, B_dominates = utl.DblsParetoMin(A.Ovas, B.Ovas)
			}
			return
		}
		B_dominates = true
		return
	}
	if B_nviolations > 0 {
		A_dominates = true
		return
	}
	A_dominates, B_dominates = utl.DblsParetoMin(A.Ovas, B.Ovas)
	return
}
コード例 #2
0
ファイル: solution.go プロジェクト: cpmech/goga
// Compare compares two solutions
func (A *Solution) Compare(B *Solution) (A_dominates, B_dominates bool) {
	var A_nviolations, B_nviolations int
	for i := 0; i < len(A.Oor); i++ {
		if A.Oor[i] > 0 {
			A_nviolations++
		}
		if B.Oor[i] > 0 {
			B_nviolations++
		}
	}
	if A_nviolations > 0 {
		if B_nviolations > 0 {
			if A_nviolations < B_nviolations {
				A_dominates = true
				return
			}
			if B_nviolations < A_nviolations {
				B_dominates = true
				return
			}
			A_dominates, B_dominates = utl.DblsParetoMin(A.Oor, B.Oor)
			if !A_dominates && !B_dominates {
				A_dominates, B_dominates = utl.DblsParetoMin(A.Ova, B.Ova)
			}
			return
		}
		B_dominates = true
		return
	}
	if B_nviolations > 0 {
		A_dominates = true
		return
	}
	A_dominates, B_dominates = utl.DblsParetoMin(A.Ova, B.Ova)
	return
}
コード例 #3
0
ファイル: simplefltprob.go プロジェクト: postfix/goga-1
func (o *SimpleFltProb) find_best() (x, f, g, h []float64) {
	chk.IntAssertLessThan(0, o.Nfeasible) // 0 < nfeasible
	nx := len(o.C.RangeFlt)
	x = make([]float64, nx)
	f = make([]float64, o.nf)
	g = make([]float64, o.ng)
	h = make([]float64, o.nh)
	copy(x, o.Xbest[0])
	o.Fcn(f, g, h, x)
	for i := 1; i < o.Nfeasible; i++ {
		o.Fcn(o.ff[0], o.gg[0], o.hh[0], o.Xbest[i])
		_, other_dom := utl.DblsParetoMin(f, o.ff[0])
		if other_dom {
			copy(x, o.Xbest[i])
			copy(f, o.ff[0])
			copy(g, o.gg[0])
			copy(h, o.hh[0])
		}
	}
	return
}
コード例 #4
0
ファイル: individual.go プロジェクト: postfix/goga-1
// IndCompareProb compares individual 'A' with another one 'B' using probabilistic Pareto method
func IndCompareProb(A, B *Individual, φ float64) (A_dominates bool) {
	var A_nviolations, B_nviolations int
	for i := 0; i < len(A.Oors); i++ {
		if A.Oors[i] > 0 {
			A_nviolations++
		}
		if B.Oors[i] > 0 {
			B_nviolations++
		}
	}
	if A_nviolations > 0 {
		if B_nviolations > 0 {
			if A_nviolations < B_nviolations {
				A_dominates = true
				return
			}
			if B_nviolations < A_nviolations {
				A_dominates = false
				return
			}
			var B_dominates bool
			A_dominates, B_dominates = utl.DblsParetoMin(A.Oors, B.Oors)
			if !A_dominates && !B_dominates {
				A_dominates = utl.DblsParetoMinProb(A.Ovas, B.Ovas, φ)
			}
			return
		}
		A_dominates = false
		return
	}
	if B_nviolations > 0 {
		A_dominates = true
		return
	}
	A_dominates = utl.DblsParetoMinProb(A.Ovas, B.Ovas, φ)
	return
}
コード例 #5
0
ファイル: simplefltprob.go プロジェクト: postfix/goga-1
// Run runs optimisations
func (o *SimpleFltProb) Run(verbose bool) {

	// benchmark
	if verbose {
		time0 := time.Now()
		defer func() {
			io.Pfblue2("\ncpu time = %v\n", time.Now().Sub(time0))
		}()
	}

	// run all trials
	for itrial := 0; itrial < o.C.Ntrials; itrial++ {

		// reset populations
		if itrial > 0 {
			for id, isl := range o.Evo.Islands {
				isl.Pop = o.C.PopFltGen(id, o.C)
				isl.CalcOvs(isl.Pop, 0)
				isl.CalcDemeritsAndSort(isl.Pop)
			}
		}

		// run evolution
		o.Evo.Run()

		// results
		xbest := o.Evo.Best.GetFloats()
		o.Fcn(o.ff[0], o.gg[0], o.hh[0], xbest)

		// check if best is unfeasible
		unfeasible := false
		for _, g := range o.gg[0] {
			if g < 0 {
				unfeasible = true
				break
			}
		}
		for _, h := range o.hh[0] {
			if math.Abs(h) > o.C.Eps1 {
				unfeasible = true
				break
			}
		}

		// feasible results
		if !unfeasible {
			for i, x := range xbest {
				o.Xbest[o.Nfeasible][i] = x
			}
			o.Nfeasible++
		}

		// message
		if verbose {
			io.Pfyel("%3d x*="+o.NumfmtX+" f="+o.NumfmtF, itrial, xbest, o.ff[0])
			if unfeasible {
				io.Pfred(" unfeasible\n")
			} else {
				io.Pfgreen(" ok\n")
			}
		}

		// best populations
		if o.C.DoPlot {
			if o.Nfeasible == 1 {
				o.PopsBest = o.Evo.GetPopulations()
			} else {
				fcur := utl.DblCopy(o.ff[0])
				o.Fcn(o.ff[0], o.gg[0], o.hh[0], o.Xbest[o.Nfeasible-1])
				cur_dom, _ := utl.DblsParetoMin(fcur, o.ff[0])
				if cur_dom {
					o.PopsBest = o.Evo.GetPopulations()
				}
			}
		}
	}
}