Dear Julians

I am solving a model in a recursive manner (backwards induction/dynamic 
programming). At each stage (I know how many), there is at least one 
solution. If there was only one solution, I would probably do:

type Sol
    ....
    variables characterizing a solution
    ....
end

and create a container solution = Sol[]. Starting from the last stage I 
would solve the stage, and save the solution using push!(solution, 
Sol(...)). This would give me the solutions from each stage in reverse 
order (or the order in which they were solved) in 'solutions'.

The thing is, sometimes there can be multiple solutions in a stage (I know 
the upper bound though, say 5). So what I did was to create

type Stage
    Sols::Sol
end

stages = Stage[]
sizehint!(stages, numberofstages)
push!(stages, Stage(Sol[]))

When solving the last stage I simply do a push!(stages[1].Sols[i], 
Sol(...)) for each solution found. Stepping back, I save solutions in the 
second last period by

push!(stages,Stage(Sol[]))
for i = 1:number_of_solutions
    push(stages[2].Sols[i], Sol(...))
end

and move on to the third last stage. 

My question is, am I over-engineering this? In some way it works, but I 
just feels like I am doing it in a stupid way.

If you need me to clarify, please ask.

Patrick

Reply via email to