Exemple #1
0
func (m Method) updateDb(nsearch, npoll *int, step float64) {
	if m.Db == nil {
		return
	}

	tx, err := m.Db.Begin()
	if err != nil {
		panic(err.Error())
	}
	defer tx.Commit()

	s1 := "INSERT INTO " + TblPolls + " (iter,val,posid) VALUES (?,?,?);"
	for _, p := range m.Poller.Points() {
		_, err := tx.Exec(s1, m.count, p.Val, p.HashSlice())
		if checkdberr(err) {
			return
		}
	}

	glob := m.Curr
	s2 := "INSERT INTO " + TblInfo + " (iter,step,nsearch, npoll,val,posid) VALUES (?,?,?,?,?,?);"
	_, err = tx.Exec(s2, m.count, step, *nsearch, *npoll, glob.Val, glob.HashSlice())
	if checkdberr(err) {
		return
	}

	pts := m.Poller.Points()
	pts = append(pts, glob)
	err = optim.RecordPointPos(tx, pts...)
	if checkdberr(err) {
		return
	}
}
Exemple #2
0
func (m *Method) updateDb(mesh optim.Mesh) {
	if m.Db == nil {
		return
	}

	tx, err := m.Db.Begin()
	if err != nil {
		panic(err.Error())
	}
	defer tx.Commit()

	s0, err := tx.Prepare("INSERT INTO " + TblParticles + " (particle,iter,val,posid,velid,vel) VALUES (?,?,?,?,?,?);")
	if checkdberr(err) {
		return
	}
	s0b, err := tx.Prepare("INSERT INTO " + TblParticlesMeshed + " (particle,iter,val,posid) VALUES (?,?,?,?);")
	if checkdberr(err) {
		return
	}
	s1, err := tx.Prepare("INSERT INTO " + TblParticlesBest + " (particle,iter,best,posid) VALUES (?,?,?,?);")
	if checkdberr(err) {
		return
	}

	pts := []*optim.Point{}

	for _, p := range m.Pop {
		vel := &optim.Point{Pos: p.Vel}
		pts = append(pts, p.Point)
		pts = append(pts, p.Best) // best might be a projected location and not present in normal eval points
		pts = append(pts, vel)

		_, err := s0.Exec(p.Id, m.iter, p.Val, p.HashSlice(), vel.HashSlice(), p.L2Vel())
		if checkdberr(err) {
			return
		}

		_, err = s1.Exec(p.Id, m.iter, p.Best.Val, p.Best.HashSlice())
		if checkdberr(err) {
			return
		}

		pp := &optim.Point{mesh.Nearest(p.Pos), p.Val}
		_, err = s0b.Exec(p.Id, m.iter, p.Val, pp.HashSlice())
		if checkdberr(err) {
			return
		}
	}

	s2, err := tx.Prepare("INSERT INTO " + TblBest + " (iter,val,posid) VALUES (?,?,?);")
	glob := m.best
	_, err = s2.Exec(m.iter, glob.Val, glob.HashSlice())
	if checkdberr(err) {
		return
	}

	pts = append(pts, glob)
	err = optim.RecordPointPos(tx, pts...)
	if checkdberr(err) {
		return
	}
}