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

Revision 61c70cc2309b155b4f4dc31a92ce60373b073c1e authored by Max Göttlicher on 26 April 2023, 13:35:20 UTC, committed by Max Göttlicher on 26 April 2023, 13:35:20 UTC
working smith initialization
1 parent c54e504
  • Files
  • Changes
  • f95134a
  • /
  • 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.

  • revision
  • directory
  • content
revision badge
swh:1:rev:61c70cc2309b155b4f4dc31a92ce60373b073c1e
directory badge Iframe embedding
swh:1:dir:cdfb723c3830fcd3ed861b5ec95331e7a52a6b72
content badge Iframe embedding
swh:1:cnt:3116e2c22d2100be13d7f12c13405bc5f129f563

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.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
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 "utility.hpp"
#include <mpgraphs/graph.hpp>
#include <mpgraphs/vecmap.hpp>
#include <mpgraphs/vecset.hpp>

namespace pds {

enum class SolveState {
    Optimal,
    Timeout,
    Infeasible,
    Heuristic,
    Other
};

struct SolveResult {
    size_t lower;
    size_t upper;
    SolveState state;
};

SolveState combineSolveState(SolveState first, SolveState second);

enum class PmuState : signed char {
    Blank = 0,
    Active = 1,
    Inactive = -1
};

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

#ifdef USE_HASHMAP
using PowerGrid = mpgraphs::MapGraph<Bus, mpgraphs::Empty, mpgraphs::EdgeDirection::Undirected>;
using ObservationGraph = mpgraphs::MapGraph<mpgraphs::Empty, mpgraphs::Empty, mpgraphs::EdgeDirection::Bidirectional>;
using VertexSet = mpgraphs::set<PowerGrid::VertexDescriptor>;
template<typename T>
using VertexMap = mpgraphs::map<PowerGrid::VertexDescriptor, T>;
#else
using Timestamp = std::uint8_t;
using PowerGrid = mpgraphs::VecGraph<Bus, mpgraphs::EdgeDirection::Undirected, true, Timestamp, std::uint32_t>;
using ObservationGraph = mpgraphs::VecGraph<mpgraphs::Empty, mpgraphs::EdgeDirection::Bidirectional, true, Timestamp>;
using VertexSet = mpgraphs::VecSet<PowerGrid::VertexDescriptor, Timestamp>;
template<typename T>
using VertexMap = mpgraphs::VecMap<PowerGrid::VertexDescriptor, T, Timestamp>;
#endif
using VertexList = std::vector<PowerGrid::VertexDescriptor>;

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::VertexDescriptor;
private:
    VertexMap<ssize_t> m_unobserved_degree;
    VertexSet m_seen;
    size_t m_numActive;
    size_t m_numInactive;
    PowerGrid m_graph;
    ObservationGraph m_dependencies;
    //mpgraphs::MapGraph<mpgraphs::Empty, mpgraphs::Empty, mpgraphs::EdgeDirection::Bidirectional> m_dependencies;

    void propagate(std::vector<Vertex>& queue);

    bool observe(Vertex vertex, Vertex origin);
    bool observeOne(Vertex vertex, Vertex origin, std::vector<Vertex>& queue);

    inline bool disableLowDegreeRecursive(
            PowerGrid::VertexDescriptor start,
            VertexSet& seen
    );

public:
    PdsState();
    explicit PdsState(PowerGrid&& graph);

    explicit PdsState(const PowerGrid& graph);

    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);

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

    [[nodiscard]] inline PmuState activeState(Vertex vertex) const { return m_graph[vertex].pmu; }

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

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

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

    [[nodiscard]] inline bool isObserved(Vertex vertex) const { return m_dependencies.hasVertex(vertex); }

    [[nodiscard]] inline bool isObservingEdge(Vertex source, Vertex target) const { return m_dependencies.hasEdge(source, target); }

    [[nodiscard]] inline size_t unobservedDegree(Vertex v) const {
        assert(m_unobserved_degree.at(v) == ranges::distance(m_graph.neighbors(v) | ranges::views::filter([this](auto v) { return !isObserved(v);})));
        return m_unobserved_degree.at(v);
    }

    bool setActive(Vertex vertex);

    bool unsetActive(Vertex vertex);

    bool setInactive(Vertex vertex);

    bool setBlank(Vertex vertex);

    [[nodiscard]] inline bool allObserved() const {
        return numObserved() == graph().numVertices();
    }

    [[nodiscard]] inline size_t numObserved() const {
        return m_dependencies.numVertices();
    }

    [[nodiscard]] inline size_t numUnobserved() const {
        return graph().numVertices() - numObserved();
    }

    [[nodiscard]] inline size_t numActive() const {
        assert(ranges::distance(graph().vertices() | ranges::views::filter([this](auto v) { return isActive(v); })) == (ssize_t)m_numActive);
        return m_numActive;
    }

    [[nodiscard]] inline size_t numInactive() const {
        assert(ranges::distance(graph().vertices() | ranges::views::filter([this](auto v) { return isInactive(v); })) == (ssize_t)m_numInactive);
        return m_numInactive;
    }

    [[nodiscard]] inline size_t numBlank() const {
        return graph().numVertices() - numActive() - numInactive();
    }

    [[nodiscard]] inline size_t numZeroInjection() const {
        return ranges::distance(graph().vertices() | ranges::views::filter([this](auto v) { return isZeroInjection(v); }));
    }

    [[nodiscard]] inline const PowerGrid& graph() const { return m_graph; }
    [[nodiscard]] inline const auto& observationGraph() const { return m_dependencies; }

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

    bool collapseLeaves();

    bool disableLowDegree();

    bool reduceObservedNonZi();

    bool collapseDegreeTwo();

    bool disableObservationNeighborhood();

    bool activateNecessaryNodes();

    bool collapseObservedEdges();

    [[nodiscard]] std::vector<PdsState> subproblems() const;

    void applySubsolution(const PdsState& other);

};

} // namespace pds

#endif //PDS_PDS_HPP
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

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