本文整理匯總了Golang中github.com/cpmech/goga.Optimiser.CxInt方法的典型用法代碼示例。如果您正苦於以下問題:Golang Optimiser.CxInt方法的具體用法?Golang Optimiser.CxInt怎麽用?Golang Optimiser.CxInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cpmech/goga.Optimiser
的用法示例。
在下文中一共展示了Optimiser.CxInt方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runone
func runone(ncpu int) (nsol, tf int, elaspsedTime time.Duration) {
// input filename
fn, fnkey := io.ArgToFilename(0, "ground10", ".sim", true)
// GA parameters
var opt goga.Optimiser
opt.Read("ga-" + fnkey + ".json")
opt.GenType = "rnd"
nsol, tf = opt.Nsol, opt.Tf
postproc := true
if ncpu > 0 {
opt.Ncpu = ncpu
postproc = false
}
// FEM
data := make([]*FemData, opt.Ncpu)
for i := 0; i < opt.Ncpu; i++ {
data[i] = NewData(fn, fnkey, i)
}
io.Pforan("MaxWeight = %v\n", data[0].MaxWeight)
// set integers
if data[0].Opt.BinInt {
opt.CxInt = goga.CxInt
opt.MtInt = goga.MtIntBin
opt.BinInt = data[0].Ncells
}
// set floats
opt.FltMin = make([]float64, data[0].Nareas)
opt.FltMax = make([]float64, data[0].Nareas)
for i := 0; i < data[0].Nareas; i++ {
opt.FltMin[i] = data[0].Opt.Amin
opt.FltMax[i] = data[0].Opt.Amax
}
// initialise optimiser
opt.Nova = 2 // weight and deflection
opt.Noor = 4 // mobility, feasibility, maxdeflection, stress
opt.Init(goga.GenTrialSolutions, func(sol *goga.Solution, cpu int) {
mob, fail, weight, umax, _, errU, errS := data[cpu].RunFEM(sol.Int, sol.Flt, 0, false)
sol.Ova[0] = weight
sol.Ova[1] = umax
sol.Oor[0] = mob
sol.Oor[1] = fail
sol.Oor[2] = errU
sol.Oor[3] = errS
}, nil, 0, 0, 0)
// initial solutions
var sols0 []*goga.Solution
if false {
sols0 = opt.GetSolutionsCopy()
}
// benchmark
initialTime := time.Now()
defer func() {
elaspsedTime = time.Now().Sub(initialTime)
}()
// solve
opt.Verbose = true
opt.Solve()
goga.SortByOva(opt.Solutions, 0)
// post processing
if !postproc {
return
}
// check
nfailed, front0 := goga.CheckFront0(&opt, true)
// save results
var log, res bytes.Buffer
io.Ff(&log, opt.LogParams())
io.Ff(&res, PrintSolutions(data[0], opt.Solutions))
io.Ff(&res, io.Sf("\n\nnfailed = %d\n", nfailed))
io.WriteFileVD("/tmp/goga", fnkey+".log", &log)
io.WriteFileVD("/tmp/goga", fnkey+".res", &res)
// plot Pareto-optimal front
feasibleOnly := true
plt.SetForEps(0.8, 350)
if strings.HasPrefix(fnkey, "ground10") {
_, ref, _ := io.ReadTable("p460_fig300.dat")
plt.Plot(ref["w"], ref["u"], "'b-', label='reference'")
}
fmtAll := &plt.Fmt{L: "final solutions", M: ".", C: "orange", Ls: "none", Ms: 3}
fmtFront := &plt.Fmt{L: "final Pareto front", C: "r", M: "o", Ms: 3, Ls: "none"}
goga.PlotOvaOvaPareto(&opt, sols0, 0, 1, feasibleOnly, fmtAll, fmtFront)
plt.Gll("weight ($f_0$)", "deflection ($f_1)$", "") //, "leg_out=1, leg_ncol=4, leg_hlen=1.5")
if strings.HasPrefix(fnkey, "ground10") {
plt.AxisRange(1800, 14000, 1, 6)
}
// plot selected results
//.........這裏部分代碼省略.........