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

https://gitlab.com/Aldorn/pds-code
15 April 2026, 07:13:25 UTC
  • Code
  • Branches (8)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/dev
    • refs/heads/fortsolving
    • refs/heads/grb-callback
    • refs/heads/master
    • refs/heads/mip_modeling
    • refs/heads/setgraph
    • refs/heads/smithhicks
    • refs/heads/star-bound
    No releases to show
  • d80b87c
  • /
  • drawGrid.cpp
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

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
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:e914a8a2df2b49cd55625bb7a5f9595428a1877b
origin badgedirectory badge
swh:1:dir:d80b87cb9b3a8dd091b65c80cf10f1ef7c10de13
origin badgerevision badge
swh:1:rev:2ae686a997ec04c8c6441ec8ebea76188e772e80
origin badgesnapshot badge
swh:1:snp:7a4cd2a5ec73a061be17605597c4b1660b799026

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
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 2ae686a997ec04c8c6441ec8ebea76188e772e80 authored by Max Göttlicher on 15 April 2023, 08:57:57 UTC
testing smith hicks weighted neighborhood
Tip revision: 2ae686a
drawGrid.cpp
#include "pds.hpp"
#include "graphio.hpp"
#include "draw_grid.hpp"

#include <boost/program_options.hpp>
#include <fmt/format.h>

#include <ogdf/energybased/FMMMLayout.h>
#include <ogdf/energybased/fmmm/FMMMOptions.h>

void writeLayout(const pds::Layout& layout, const std::string& filename) {
    FILE* outfile = fopen(filename.c_str(), "wb");
    if (outfile == nullptr) throw std::system_error(std::error_code(errno, std::system_category()));
    fmt::print(outfile, "Layout V1.0\n");
    for (auto [k, v]: layout) {
        fmt::print(outfile, "{} {} {}\n", k, v.x, v.y);
    }
    fclose(outfile);
}

struct ParseError : std::exception {
    std::string reason;
    ParseError(const std::string& reason, size_t line) : reason(fmt::format("{}: {}", line, reason)) { }
    const char * what() const noexcept override { return reason.c_str(); }
};

std::vector<std::string_view> split(const std::string_view& in, char delim) {
    std::vector<std::string_view> pieces;
    size_t start = 0;
    size_t end;
    while (start != std::string::npos) {
        end = in.find(delim, start);
        pieces.emplace_back(in.substr(start, end - start));
        if (end == std::string::npos) {
            start = std::string::npos;
        } else {
            start = end + 1;
        }

    }
    return pieces;
}

pds::Layout readLayout(const std::string& filename) {
    std::ifstream infile(filename);
    std::string line;
    size_t lineno = 0;
    pds::Layout layout;
    std::getline(infile, line);
    ++lineno;
    if (line != "Layout V1.0") throw ParseError { fmt::format("unknown format: {}", line), lineno };
    while (infile) {
        std::getline(infile, line);
        ++lineno;
        auto pieces = split(line, ' ');
        if (pieces.size() == 1 && pieces[0] == "") continue; // empty line
        if (pieces.size() != 3) throw ParseError { "not a triple", lineno };
        try {
            long v = std::stoi(std::string{pieces[0]});
            double x = std::stoi(std::string{pieces[1]});
            double y = std::stoi(std::string{pieces[2]});
            layout[v] = {x, y};
        } catch(const std::exception& ex) {
            throw ParseError { fmt::format("could not read number: {}", ex.what()), lineno };
        }
    }
    return layout;
}

void restrictLayout(pds::Layout& layout, const pds::PowerGrid& graph) {
    pds::set<long> ids = ranges::transform_view(graph.vertices(), [&graph](auto v) { return graph[v].id; }) | ranges::to<pds::set<long>>;
    erase_if(layout,[&ids](const auto& kv) { return !ids.contains(kv.first);});
}

int main(int argc, const char** argv) {
    namespace po = boost::program_options;
    using std::string;
    using namespace pds;

    po::options_description desc;
    desc.add_options()
            ("layout,l", po::value<string>(), "load layout from file")
            ("save-layout,s", po::value<string>(), "save layout to file")
            ("graph,g", po::value<string>()->required(), "graph file")
            ("draw,d", po::value<string>(), "create graph svg file")
            ("layout-bounds,b", "use bounds from layout for drawing")
            ("help,h", "show this help")
    ;
    po::positional_options_description pos;
    pos.add("graph", 1);

    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).options(desc).positional(pos).run(), vm);
    if (vm.count("help")) {
        desc.print(std::cout);
        return EXIT_FAILURE;
    }

    auto graph = readAutoGraph(vm["graph"].as<string>());

    Layout layout;
    if (vm.count("layout")) {
        layout = readLayout(vm["layout"].as<string>());
        if (!vm.count("layout-bounds")) {
            restrictLayout(layout, graph);
        }
    } else {
        layout = layoutGraph(graph);
    }
    if (vm.count("draw")) {
        PdsState state(graph);
        drawGrid(state, vm["draw"].as<string>(), layout);
    }
    if (vm.count("save-layout")) {
        writeLayout(layout, vm["save-layout"].as<string>());
    }
}

back to top

Software Heritage — Copyright (C) 2015–2026, 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