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 5a44a1183318dd6f9b5dc5eed204695e90703a4f authored by Max Göttlicher on 15 February 2023, 10:22:34 UTC, committed by Max Göttlicher on 15 February 2023, 10:22:34 UTC
implementing on star bound
1 parent 1898f1b
  • Files
  • Changes
  • 1507a66
  • /
  • percentPropagating.cpp
Raw File Download
Permalinks

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:5a44a1183318dd6f9b5dc5eed204695e90703a4f
directory badge Iframe embedding
swh:1:dir:1507a66053c71295e48b63bea718eb4e8b850553
content badge Iframe embedding
swh:1:cnt:d4b6609455dacf81ead09f9d2e32402dc6350cd6
Citations

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 ...
percentPropagating.cpp
//
// Created by max on 23.01.23.
//
#include <boost/program_options.hpp>
#include <iostream>
#include <fmt/format.h>
#include <range/v3/all.hpp>

#include "graphio.hpp"

int main(int argc, char** argv) {
    namespace po = boost::program_options;
    using std::string, std::vector;
    po::options_description desc;
    desc.add_options()
            ("graph,f", po::value<string>()->required(), "graph input file")
            ("outgraph,o", po::value<string>()->required(), "output graph")
            ("percentage,p", po::value<int>()->default_value(50), "percentage of propagating vertices to keep")
            ("all-non-prop,a", "consider all input vertices non-propagating")
            ("help,h", "show this message")
    ;
    po::positional_options_description pos;
    pos.add("graph", 1).add("outgraph", 1);
    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).options(desc).positional(pos).run(), vm);
    po::notify(vm);

    if (vm.count("help")) {
        std::cerr << "selects a subset of non-propagating vertices based on the non-propagating vertices in the input." << desc << std::endl;
        return 1;
    }
    auto graph = pds::readAutoGraph(vm["graph"].as<string>());
    if (vm.count("all-non-prop")) {
        for (auto v: graph.vertices()) {
            graph.getVertex(v).zero_injection = false;
        }
    }
    vector<pds::PowerGrid::VertexDescriptor> vertices;
    vertices.reserve(graph.numVertices());
    for (auto v: graph.vertices()) { if (!graph.getVertex(v).zero_injection) vertices.push_back(v); }
    ranges::shuffle(vertices);
    size_t numKeep = vertices.size() * vm["percentage"].as<int>() / 100;
    fmt::print("{} → {}\n", vm["graph"].as<string>(), vm["outgraph"].as<string>());
    fmt::print("keeping {} of {} non-propagating vertices", numKeep, vertices.size());
    for (size_t i = numKeep; i < vertices.size(); ++i) {
        graph.getVertex(vertices[i]).zero_injection = true;
    }
    size_t remaining = 0;
    for (auto v: graph.vertices()) { remaining += !graph.getVertex(v).zero_injection; }
    fmt::print(" ({})\n", remaining);
    pds::writePds(graph, vm["outgraph"].as<string>());
}
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 ...

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— Contact— JavaScript license information— Web API

back to top