MATPOWER / most

MOST – MATPOWER Optimal Scheduling Tool, for steady-state power systems scheduling problems.
https://matpower.org/
Other
31 stars 11 forks source link

Error in 'most()' function during logical comparison with multiple storage systems #37

Closed Keir-Steegstra closed 12 months ago

Keir-Steegstra commented 1 year ago

I have encountered a bug in the most() function while running simulations using two storage systems (ns = 2). The bug manifests during the logical comparison of arrays within the code segment that validates InitialStorageLowerBound and InitialStorageUpperBound against InitialStorage. Specifically, the error arises due to the direct array comparison without catering for multiple storage systems. Here's the error message generated:

mainfarm.m Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values. Error in most (line 278) mdi.Storage.InitialStorageLowerBound ~= mdi.Storage.InitialStorage Error in mainfarm_two (line 55) mdo = most(mdi, mpopt); % Run most simulation

A potential resolution for this issue is to modify the direct comparison to employ the any() function, thereby allowing the code to accommodate scenarios with multiple storage units possessing varying initial storage values. Below is the modified code segment:

elseif max(mdi.idx.nj) == 1 && ~mo.ForceCyclicStorage && ...
        any(mdi.Storage.InitialStorageLowerBound ~= mdi.Storage.InitialStorage)
    warning('Deterministic problem with ForceCyclicStorage = 0, setting InitialStorageLowerBound = InitialStorage')
    mdi.Storage.InitialStorageLowerBound = mdi.Storage.InitialStorage;
end
...
elseif max(mdi.idx.nj) == 1 && ~mo.ForceCyclicStorage && ...
            any(mdi.Storage.InitialStorageUpperBound ~= mdi.Storage.InitialStorage)
    warning('Deterministic problem with ForceCyclicStorage = 0, setting InitialStorageUpperBound = InitialStorage')
    mdi.Storage.InitialStorageUpperBound = mdi.Storage.InitialStorage;
end

This alteration ensures the code can handle multiple storage units with potentially different initial storage values without triggering errors during logical comparisons.

rdzman commented 12 months ago

Thanks for finding and reporting this, @Keir-Steegstra.