How about using a dictionary of vectors?
i.e.
T_GENERATING_BUS = Dict()
for k in BUS
for j=1:gmax
if BUS_T[j] == k
if k in keys(T_GENERATING_BUS)
push!(T_GENERATING_BUS[k], j)
else
T_GENERATING_BUS[k] = [j]
end
end
end
end
On Saturday, April 25, 2015 at 5:17:16 PM UTC-4, Fabrizio wrote:
>
> Thanks Jemeson,
>
> but it seems not enough, indeed T_GENERATING_BUS must be a collection of k
> (=maximum(BUS)) but also with enough space to contain an - unknown a priori
> - number of Power_Gen attached to it. Moreover if i change the code as
> suggested i get the following error
>
> ERROR: `convert` has no method matching convert(::Type{Set{Any}},
> ::Array{Any,1})
>
> Fabrizio
>
> On Saturday, April 25, 2015 at 8:41:56 PM UTC+2, [email protected]
> wrote:
>>
>> Hi, very newby in Julia/JuMP, my problem is
>>
>> i have a set of power gen and attached nodes in a grid in this format
>>
>> PowerGen_ID Node
>> 1 1
>> 2 2
>> 3 1
>> 4 2
>>
>> i would like to construct a set "T_GENERATING_BUS" for each node that
>> contains the Power Gen attached to it
>> i.e.
>> T_GENERATING_BUS[1]={1,3};
>> T_GENERATING_BUS[2]={2,4};
>>
>> i tried something like:
>>
>> T_GENERATING_BUS = Set[]
>>
>> for k in BUS
>> for j=1:gmax
>> if BUS_T[j] == k
>> T_GENERATING_BUS[k] = union(T_GENERATING_BUS[k],j)
>> end
>> end
>> end
>>
>> but got an error bound
>> ERROR: BoundsError()
>> in getindex at array.jl:246 (repeats 2 times)
>> while loading E:\CodiciSorgente\ProgrammiJulia\UCOTS.jl, in expression
>> starting on line 101
>>
>> the problem is that i don't know how to increase the dim of
>> T_GENERATING_BUS
>>
>> Any hints?
>>
>> Thanks
>>
>> Fabrizio
>>
>>