FreeGCS 3D constraints

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
ickby
Posts: 2922
Joined: Wed Oct 05, 2011 7:36 am

Re: FreeGCS 3D constraints

Postby ickby » Tue Nov 01, 2011 9:38 pm

now it turned out this is a bitch. I've spend quite some time trying to get the constraints working in an reliable way, but cant find a solution that works in more than 50% of the test cases. I checked my math with free available solvers (namely octave), turns out my functions are working. This means I have to dig deep and change basic solver algorithms, making the fork needed earlier than I though.

I have some ideas what I can do, starting with changing the linesearch to hold the wolf condition, but this will require some serious reading and therefore quite some time. I will keep you informed of my progress.

Greetings,
Stefan
logari81
Posts: 654
Joined: Mon Jun 14, 2010 6:00 pm

Re: FreeGCS 3D constraints

Postby logari81 » Tue Nov 01, 2011 9:49 pm

Have you tried to split your system into two subsystems and use the corresponding solver? It is much more stable than the normal one.
ickby
Posts: 2922
Joined: Wed Oct 05, 2011 7:36 am

Re: FreeGCS 3D constraints

Postby ickby » Wed Nov 02, 2011 10:48 am

I haven't tried the two system solver yet, but good to know that this one is more stable! But splitting is not an option as I struggle with a one-constraint system, the most basic test case.

The octave optimization function sqp is quite impressive, manages to solve the systems exactly without the gradients supplied. They calculate then with finite differences and calculate the hessian with an BFGS update. The Sqp method (sequential quadratic programming) reduces for an unconstrained nonlinear function (our case) to Newtons method, so basically they do the same thing as we are doing in the solver (when gradients supplied). Thats nice to know, as it shows that freeGCS is capable of doing what we need :) I may even look in octaves implementation to find out what they do different.
logari81
Posts: 654
Joined: Mon Jun 14, 2010 6:00 pm

Re: FreeGCS 3D constraints

Postby logari81 » Wed Nov 02, 2011 1:39 pm

The two subsystem solver is sqp based. The implementation is based on Nocedal's book. I had checked octaves implementation and there are no big differences. It would be really useful also for the 2D solver to improve/rewrite the single subsystem solver. It causes a lot of problems. Actually the single subsystem solver should be more consistent with the two subsystems solver.
ickby
Posts: 2922
Joined: Wed Oct 05, 2011 7:36 am

Re: FreeGCS 3D constraints

Postby ickby » Wed Nov 02, 2011 3:17 pm

That is interesting, haven't looked on the two systems solver too closely. I will catch up on this implementation. What was your intension of using a sqp solver there? I thought they are only for constrained functions?
logari81
Posts: 654
Joined: Mon Jun 14, 2010 6:00 pm

Re: FreeGCS 3D constraints

Postby logari81 » Wed Nov 02, 2011 3:46 pm

yes, the two subsystems solver solves one of the subystems (subsysB) using the other subsystem (subsysA) as a constraint. This is a nonlinear constrained system. QP solves linear constrained systems but it is also used as a single step in the nonlinear case inside the SQP algorithm.

At the moment we exploit this only for mouse dragging. Splitting the whole system into real constraints and dragging constraints. This is the reason for the success of the solver so far in the sketcher.

Later on, when we'll do the partitioning of the problem, we may exploit the two subsystems solver in order to combine the partitioned subsystems.
ickby
Posts: 2922
Joined: Wed Oct 05, 2011 7:36 am

Re: FreeGCS 3D constraints

Postby ickby » Tue Nov 08, 2011 2:55 pm

Hello,

finally I've managed to create some working code. http://ubuntuone.com/6nFP4CkylZXjFRaswmoP6S is a small video which shows the results, a little assembly created with constraints. Some constraint types are still missing and it's not stable in all cases, but I think this is a big step.

As mentioned before I've rewritten the solver to get it working, changed it to the Levenberg Marquat algorithm. But this was still not enough, so i decided to change the solver to a two-step solution: first calculate all rotational constraints, after that all translational. That works pretty nice, but actually the old solver could do that as well. I've found my implementation to be more reliable (especially with the translational constraints), but maybe we need a deep comparison here.
@logari: you've mentioned stability issues with the single-subsystem solver before, maybe you could try my implementation on a few test cases with known issues? I've you're interested I could create a patch!

My next steps will be to make this more stable, clean up my code and again make it more stable :)
User avatar
yorik
Site Admin
Posts: 11567
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: FreeGCS 3D constraints

Postby yorik » Tue Nov 08, 2011 3:22 pm

Wow, things are starting! Keep up the nice work!
logari81
Posts: 654
Joined: Mon Jun 14, 2010 6:00 pm

Re: FreeGCS 3D constraints

Postby logari81 » Tue Nov 08, 2011 3:23 pm

WOW!!!!!!! That's impressive!!!
pperisin
Posts: 695
Joined: Wed Oct 20, 2010 12:29 pm

Re: FreeGCS 3D constraints

Postby pperisin » Tue Nov 08, 2011 3:25 pm

Looks really really really really cool. Great job man.


Regards
Petar