Hello Greg,
thank you for the hint with the sparse solver! But as always, after one question got answered, two others arise:
1. I tried casadi.solve(A, b, "csparse") with A, b SX symbolics, and recieved the following error:
NotImplementedError: Wrong number or type of arguments for overloaded function 'solve'.
Possible Python usages are:
solve(array(double) ,array(double) ,str,Dictionary)
solve(array(double) ,array(double) ,str)
solve(array(int) ,array(int) )
solve(array(double) ,array(double) )
solve(MX,MX,str,Dictionary)
You have: solve(SX, SX, str)
So for some reason, you can only supply an additional string when using doubles or MX symbolics, but not when using SX symbolics. Is this intended?
2. I then tried to use the LinearSolver-class as you suggested, and as far as I can tell it's working, but I was able to discover something else: when I set up the collocation method as depicted within the CasADi example pack in vdp_collocation2.py, I will initialize variables for the states that will not be used within the NLP, but handed to the solver. This happens because when initializing
entry("X",repeat=[nk+1,d+1],struct=states),
entry("U",repeat=[nk],shape=nu)
also for the last time point, the variables for the states will be repeated as for the other points in time, and therefor the last d variables will never be used. Within to the minimization, these variables will then just be set to zero, and not cause any problem here (I think). If I now (with an example model that contains 4 states) try to do as follows:
h3 = ca.vertcat((h1, h2))
lsol = ca.LinearSolver("csparse", h3.sparsity())
I receive an error message telling me
RuntimeError: The assertion "!sparsity.isSingular()" on line 48 of file "/home/casadibot/slaves/linuxbot/release-update-minimal/source/casadi/core/function/linear_solver_internal.cpp" failed.
LinearSolverInternal::init: singularity - the matrix is structurally rank-deficient. sprank(J)=2566 (in stead of 2578)
which is a discrepancy of 12 lines, which matches "4 states repeated 3 times to often". For another example I tried that contains only two states, the discrepancy is 6, which fits to my considerations. So it seems that I now have to do one of the following things:
a) either I have to prevent the states from being repeated to often, so I would have do something like "append only one more state-vector at the end of the X-entry" or
b) I have to calculate the derivatives w. r. t. all but these variables by somehow "filtering out" the last 3 repetitions values from the struct.
For both things, I do not know how to achieve them :-) but I think that a) would be the much cleaner solution. Can this be achieved in some elegant way?
Thank you for your answer!
Best regards,
Adrian