Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 18fea79
  • /
  • include
  • /
  • pds.hpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:39b52fdba048a0187190136bdc3b847c060fcd60
directory badge Iframe embedding
swh:1:dir:71742a8042ac28a004781fb674afb25d0fecb1e3

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
pds.hpp
//
// Created by max on 19.07.22.
//

#ifndef PDS_PDS_HPP
#define PDS_PDS_HPP

#include <range/v3/all.hpp>

#include <iostream>
#include <fstream>
#include <optional>

#include <fmt/core.h>
#include <fmt/ranges.h>

#include "map.hpp"
#include <setgraph/graph.hpp>

namespace pds {

enum class PmuState {
    Blank,
    Active,
    Inactive
};

struct Bus {
    std::string name;
    long id;
    bool zero_injection;
};

using PowerGrid = setgraph::SetGraph<Bus, setgraph::Empty, setgraph::EdgeDirection::Undirected>;

PowerGrid import_graphml(const std::string& filename, bool all_zero_injection = false);

bool propagate(const PowerGrid&, set<PowerGrid::vertex_descriptor>&, size_t = 1);

set<PowerGrid::vertex_descriptor> observationNeighborhood(const PowerGrid& graph, const set<PowerGrid::vertex_descriptor>& starts);

template<class T>
size_t intersectionSize(const set<T>& first, const set<T>& second) {
    size_t count = 0;
    for (auto x: first) {
        if (second.contains(x)) {
            ++count;
        }
    }
    return count;
}

template<class T>
bool isSuperset(const set <T> &container, const set <T> &other) {
    if (other.size() > container.size()) return false;
    for (auto x: other) {
        if (!container.contains(x)) return false;
    }
    return true;
}

class PdsState {
public:
    using Vertex = PowerGrid::vertex_descriptor;
private:
    pds::map<Vertex, int> m_unobserved_degree;
    pds::set<Vertex> m_deleted;
    pds::set<Vertex> m_observed;
    pds::map<Vertex, PmuState> m_active;
    PowerGrid m_graph;

    void propagate(Vertex vertex);

    void observe(Vertex vertex);

    inline bool disableLowDegreeRecursive(
            PowerGrid::vertex_descriptor start,
            set<PowerGrid::vertex_descriptor>& seen
    );

public:
    PdsState() = default;
    explicit PdsState(PowerGrid&& graph) : m_graph(graph) {
        for (auto v: graph.vertices()) {
            m_unobserved_degree.emplace(v, m_graph.degree(v));
            m_active.emplace(v, PmuState::Blank);
        }
    }

    explicit PdsState(const PowerGrid& graph) : m_graph(graph) {
        for (auto v: graph.vertices()) {
            m_unobserved_degree.emplace(v, m_graph.degree(v));
            m_active.emplace(v, PmuState::Blank);
        }
    }

    PdsState(const PdsState&) = default;
    PdsState(PdsState&&) = default;
    PdsState& operator=(const PdsState&) = default;
    PdsState& operator=(PdsState&&) = default;

    void addEdge(Vertex source, Vertex target);
    void removeVertex(Vertex v);

    inline bool isZeroInjection(Vertex vertex) const { return m_graph[vertex].zero_injection; }

    inline PmuState activeState(Vertex vertex) const { return m_active.at(vertex); }

    inline bool isActive(Vertex vertex) const { return activeState(vertex) == PmuState::Active; }

    inline bool isBlank(Vertex vertex) const { return activeState(vertex) == PmuState::Blank; }

    inline bool isInactive(Vertex vertex) const { return activeState(vertex) == PmuState::Inactive; }

    inline bool isObserved(Vertex vertex) const { return m_observed.contains(vertex); }

    inline const set<Vertex>& observed() const { return m_observed; }

    inline const map<Vertex, PmuState>& active() const { return m_active; }

    bool setActive(Vertex vertex);

    bool setInactive(Vertex vertex);

    bool setBlank(Vertex vertex);

    inline bool allObserved() const {
        return ranges::all_of(m_graph.vertices(), [this](auto v) { return m_observed.contains(v); });
    }

    inline const PowerGrid& graph() const { return m_graph; }

    inline PowerGrid && graph() { return std::move(m_graph); }

    bool collapseLeaves();

    bool disableLowDegree();

    bool reduceObservedNonZi();

    bool collapseDegreeTwo();

    bool disableObservationNeighborhood();

    bool activateNecessaryNodes();

    bool collapseObservedEdges();

    bool solveTrivial();

    std::vector<PdsState> subproblems(bool nonZiSeparators = false) const;

};


void dominate(const PowerGrid& graph, const map<PowerGrid::vertex_descriptor, PmuState>& active, set<PowerGrid::vertex_descriptor>& observed);

bool propagate(const PowerGrid& graph, set<PowerGrid::vertex_descriptor>& observed, size_t max_unobserved);

bool observed(const PowerGrid& graph, const set<PowerGrid::vertex_descriptor> & observed);

} // namespace pds

#endif //PDS_PDS_HPP

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API