func (o *PrincStrainsUp) dbg_end(s *State, ε []float64, eid, ipid int) func() { if eid == o.DbgEid && ipid == o.DbgIpId { o.DbgPco = append(o.DbgPco, utl.DblCopy(s.Sig)) return func() { o.DbgRes = append(o.DbgRes, s.GetCopy()) o.DbgSts = append(o.DbgSts, ε) o.DbgPco = append(o.DbgPco, utl.DblCopy(s.Sig)) } } return func() {} }
// Append adds a new entry {x, id} to the bins structure func (o *Bins) Append(x []float64, id int) (err error) { idx := o.CalcIdx(x) if idx < 0 { return chk.Err("point %v is out of range", x) } bin := o.FindBinByIndex(idx) if bin == nil { return chk.Err("bin index %v is out of range", idx) } xcopy := utl.DblCopy(x) entry := BinEntry{id, xcopy} bin.Entries = append(bin.Entries, &entry) return }
// 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() } } } } }