@@ -107,8 +107,9 @@ type solutionSolvingState struct {
107107 psc * planSegmentContext
108108 maxSolutions int
109109
110- seed referenceframe.FrameSystemInputs
111- linearSeed []float64
110+ seeds []referenceframe.FrameSystemInputs
111+ linearSeeds [][]float64
112+
112113 moving , nonmoving []string
113114
114115 ratios []float64
@@ -130,7 +131,7 @@ func newSolutionSolvingState(psc *planSegmentContext) (*solutionSolvingState, er
130131
131132 sss := & solutionSolvingState {
132133 psc : psc ,
133- seed : psc .start ,
134+ seeds : []referenceframe. FrameSystemInputs { psc .start } ,
134135 solutions : []* node {},
135136 failures : newIkConstraintError (psc .pc .fs , psc .checker ),
136137 startTime : time .Now (),
@@ -144,11 +145,32 @@ func newSolutionSolvingState(psc *planSegmentContext) (*solutionSolvingState, er
144145 sss .maxSolutions = defaultSolutionsToSeed
145146 }
146147
147- psc .pc .logger .Debugf ("psc.start -> seed: \n %v\n %v" , psc .start , sss .seed )
148- sss .linearSeed , err = psc .pc .lfs .mapToSlice (sss .seed )
148+ ls , err := psc .pc .lfs .mapToSlice (psc .start )
149149 if err != nil {
150150 return nil , err
151151 }
152+ sss .linearSeeds = [][]float64 {ls }
153+
154+ if len (psc .pc .lfs .dof ) <= 6 { // TODO - remove the limit
155+ ssc , err := smartSeed (psc .pc .fs , psc .pc .logger )
156+ if err != nil {
157+ return nil , fmt .Errorf ("cannot create smartSeeder: %w" , err )
158+ }
159+
160+ altSeeds , err := ssc .findSeeds (psc .goal , psc .start , psc .pc .logger )
161+ if err != nil {
162+ psc .pc .logger .Warnf ("findSeeds failed, ignoring: %v" , err )
163+ }
164+ for _ , s := range altSeeds {
165+ ls , err := psc .pc .lfs .mapToSlice (s )
166+ if err != nil {
167+ psc .pc .logger .Warnf ("mapToSlice failed? %v" , err )
168+ continue
169+ }
170+ sss .seeds = append (sss .seeds , s )
171+ sss .linearSeeds = append (sss .linearSeeds , ls )
172+ }
173+ }
152174
153175 sss .moving , sss .nonmoving = sss .psc .motionChains .framesFilteredByMovingAndNonmoving ()
154176
@@ -161,12 +183,12 @@ func newSolutionSolvingState(psc *planSegmentContext) (*solutionSolvingState, er
161183}
162184
163185func (sss * solutionSolvingState ) computeGoodCost (goal referenceframe.FrameSystemPoses ) error {
164- sss .ratios = sss .psc .pc .lfs .inputChangeRatio (sss .psc .motionChains , sss .seed ,
186+ sss .ratios = sss .psc .pc .lfs .inputChangeRatio (sss .psc .motionChains , sss .seeds [ 0 ], /* maybe use the best one? */
165187 sss .psc .pc .planOpts .getGoalMetric (goal ), sss .psc .pc .logger )
166188
167189 adjusted := []float64 {}
168190 for idx , r := range sss .ratios {
169- adjusted = append (adjusted , sss .psc .pc .lfs .jog (idx , sss .linearSeed [ idx ], r ))
191+ adjusted = append (adjusted , sss .psc .pc .lfs .jog (idx , sss .linearSeeds [ 0 ][ idx ] /* match above when we change */ , r ))
170192 }
171193 step , err := sss .psc .pc .lfs .sliceToMap (adjusted )
172194 if err != nil {
@@ -314,6 +336,9 @@ func (sss *solutionSolvingState) shouldStopEarly() bool {
314336 if sss .bestScoreNoProblem < sss .goodCost / 20 {
315337 multiple = 0
316338 minMillis = 10
339+ } else if sss .bestScoreNoProblem < sss .goodCost / 15 {
340+ multiple = 1
341+ minMillis = 15
317342 } else if sss .bestScoreNoProblem < sss .goodCost / 10 {
318343 multiple = 0
319344 minMillis = 20
@@ -384,7 +409,7 @@ func getSolutions(ctx context.Context, psc *planSegmentContext) ([]*node, error)
384409 utils .PanicCapturingGo (func () {
385410 // This channel close doubles as signaling that the goroutine has exited.
386411 defer close (solutionGen )
387- _ , err := solver .Solve (ctxWithCancel , solutionGen , solvingState .linearSeed , solvingState .ratios , minFunc , psc .pc .randseed .Int ())
412+ _ , err := solver .Solve (ctxWithCancel , solutionGen , solvingState .linearSeeds , solvingState .ratios , minFunc , psc .pc .randseed .Int ())
388413 if err != nil {
389414 solveErrorLock .Lock ()
390415 solveError = err
0 commit comments