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

WIP: XnecProvider accepts paired Dangling Lines #173

Closed
wants to merge 1 commit into from

Conversation

caioluke
Copy link
Member

WORK IN PROGRESS

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce?

Feature

What is the current behavior?

XnecProvider currently accepts only Branches.

What is the new behavior (if this is a feature change)?
XnecProvider will also accept paired DanglingLines.

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

Signed-off-by: Caio Luke <caioluke97@gmail.com>
@caioluke
Copy link
Member Author

@OpenSuze @murgeyseb what do you think about this idea? Extending the XnecProvider API to also accept paired DanglingLines.

It is not finished, I will still need to do some work on the PTDF calculations and most likely in other places of the code.

But before doing so, please tell me what you think about this implementation!

Thanks

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
56.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@So-Fras So-Fras requested a review from OpenSuze October 18, 2024 10:27
@murgeyseb
Copy link
Contributor

@caioluke I think that this proposal is not a good solution as it clearly opens many potential issues in the usage of the algorithm.
I would prefer a specific implementation on your side of XnecProvider that actually does the conversion. E.G.

public class XnecProviderImpl implements XnecProvider {
    private static final Logger LOGGER = LoggerFactory.getLogger(XnecProviderImpl.class);
    private final String danglingLineId;

    public XnecProviderImpl(String danglingLineId) {
        this.danglingLineId = Objects.requireNonNull(danglingLineId);
    }

    @Override
    public Set<Branch> getNetworkElements(Network network) {
        DanglingLine danglingLine = network.getDanglingLine(danglingLineId);
        if (danglingLine == null) {
            LOGGER.warn("Branch {} was not found in network {}", danglingLineId, network.getId());
            return Collections.emptySet();
        }
        // check if dangling line is duly paired
        if (danglingLine.isPaired()) {
            return Set.of(danglingLine.getTieLine().get());
        } else {
            LOGGER.warn("DanglingLine {} is not paired: will not decompose such flows", danglingLineId);
            return Collections.emptySet();
        }
    }

    @Override
    public Set<Branch> getNetworkElements(String contingencyId, Network network) {
        return Collections.emptySet();
    }

    @Override
    public Map<String, Set<Branch>> getNetworkElementsPerContingency(Network network) {
        return Collections.emptyMap();
    }

    @Override
    public List<Contingency> getContingencies(Network network) {
        return Collections.emptyList();
    }
}

You can also add the same kind of implementation for your observers

@caioluke
Copy link
Member Author

caioluke commented Oct 18, 2024

@murgeyseb
Thank you for your reply.
Ok, I could create a XnecProviderByDanglingLineId that provides the TieLine instead.
But what I still don't get it, is how I would get in the end DecomposedFlows for my original DanglingLine...

The observer part is being handled in #171, so the only thing remaining is really the final decomposed flows.

@murgeyseb
Copy link
Contributor

@caioluke You can do something like that :

Network network = Network.read("");
Set<String> danglingLineIds = Set.of("dl1", "dl2");
Map<String, String> tieLineOfDanglingLine = danglingLineIds.stream()
        .collect(Collectors.toMap(
                Function.identity(),
                id -> network.getDanglingLine(id).getTieLine().get().getId()
        ));
XnecProvider xnecProvider = XnecProviderByIds.builder().addNetworkElementsOnBasecase(Set.copyOf(tieLineOfDanglingLine.values())).build();
FlowDecompositionResults results = new FlowDecompositionComputer().run(xnecProvider, network);
Map<String, DecomposedFlow> decomposedFlowByDanglingLine = tieLineOfDanglingLine.entrySet().stream()
        .collect(Collectors.toMap(
                entry -> entry.getKey(),
                entry -> results.getDecomposedFlowMap().get(entry.getValue())
        ));

You can use same type of trick (mapping from dangling line to tie line) in your own Observer implementation

@caioluke
Copy link
Member Author

@murgeyseb
Hmmm, interesting. I'll do some testing on my side and see what I can come up with. Thanks!

@caioluke
Copy link
Member Author

@murgeyseb
After some testing, we will keep your solution. Indeed it makes more sense to have the same flow decomposition for both paired dangling lines.
I'll close this PR and the other one too.
Thanks for the help!

@caioluke caioluke closed this Oct 28, 2024
@caioluke caioluke deleted the xnec_provider_accepts_paired_dangling_lines branch October 28, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants