Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with getVarOffset and CreateCost #14

Open
onapolitano opened this issue Jul 20, 2023 · 1 comment
Open

issue with getVarOffset and CreateCost #14

onapolitano opened this issue Jul 20, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@onapolitano
Copy link

dear all,

I'm trying to define a cost on a function that depends on the optimization variables (input and state) at each node. To do that I'm using getVarOffset(). I'm doing different tests to understand how this method works and I'm encountering issues abut the nodes where the offset variable is defined.

For example, if i do q.getVarOffset(-k) with k=n_nodes, the only node where the variable is defined is the last one and hence on this variable i can set a final cost prb.createFinalCost('q_final', q.getVarOffset(-k)). However the following error in the function setNodes() comes out :
Exception has occurred: IndexError
index 20 is out of bounds for axis 1 with size 1
because the nodes_mask is a vector of only one element and when i do nodes_mask[:, nodes] = 1 the only admissible index is nodes=0 but here is nodes=n_nodes.

Since q.getVarOffset(-n_nodes) is supposed to be the variable at the first node it makes sense for me that the only admissible node is the first one but when I try to set the cost, the only admissible node is the last one. But anyway I cannot set the cost because the only nodes that i can set is the first one,

Here a simple example of the code:
n_nodes = 20
q_n = q.getVarOffset( - 20 )
prb.createFinalCost('test_cost_qn', - q_n)

Therefore I'm wandering if you have a solution
thank you for your help

@FrancescoRuscelli FrancescoRuscelli self-assigned this Jul 21, 2023
@FrancescoRuscelli FrancescoRuscelli added the bug Something isn't working label Jul 21, 2023
@FrancescoRuscelli
Copy link
Collaborator

tentative fix at offset_fix, still need to be extensively tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants