text:
#ifndef MM_NETWORK_GRAPH_HPP
#define MM_NETWORK_GRAPH_HPP
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <deque>
#include <boost/config.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/property_map/property_map.hpp>
#include "../../src/types.hpp"
#include "../../src/reader.hpp"
#include "float.h"
#include "../../src/network.hpp"
#include <algorithm> // std::reverse
namespace MM {
class NetworkGraph
{
public:
    static constexpr double DIST_NOT_FOUND = DBL_MAX;
    /**
     *  Note here, if we construct config with config = NetworkGraphConfig(filename);
     *  it will invoke the default constructor with no argument first, as it is
     *  equivalent to first initialize config then update its content.
     */
    NetworkGraph(Network *network) {
        std::vector<Edge> *edges = network->get_edges();
        std::cout << "Construct graph from network edges start" << '\n';
        edge_descriptor e;
        bool inserted;
        g = Graph_T(); //18
        int N = edges->size();
        printf("Network edges :%d \n", N);
        for (int i = 0; i < N; ++i) {
            Edge &network_edge = (*edges)[i];
            boost::tie(e, inserted) = add_edge(network_edge.source, network_edge.target, g);
            // id is the FID read, id_attr is the external property in SHP
            g[e].id = network_edge.id;
            g[e].length = network_edge.length;
            //printf( "Edge read %d,%d,%d,%lf\n",network_edge.id,network_edge.source,network_edge.target,network_edge.length);
        }
        int Npoints = boost::num_vertices(g);
        std::cout << "Graph nodes " << Npoints << '\n';
        std::cout << "Construct graph from network edges end" << '\n';
    };
    /**
     * Precompute an UBODT with delta and save it to the file
     * @param filename [description]
     * @param delta    [description]
     */
    void precompute_ubodt(const std::string &filename, double delta) {
        std::ofstream myfile(filename);
        std::cout << "Start to generate UBODT with delta " << delta << '\n';
        myfile << "source;target;next_n;last_n;next_e;distance\n";
        vertex_iterator vi, vend;
        for (boost::tie(vi, vend) = vertices(g); vi != vend; ++vi) {
            driving_distance(*vi, delta, myfile);
        }
        myfile.close();
    };
    /**
     * Find shortest path distance from source to target
     * @param  source [description]
     * @param  target [description]
     * @return        [description]
     *
     * In case that a shortest path is not found from source
     * to target, an extremely large value is returned as
     * NO_GAP_DISTANCE.
     *
     * http://www.boost.org/doc/libs/1_55_0/libs/graph/example/dijkstra-example.cpp
     *
     */
    double single_source_target_distance(int source, int target) {
        ++calling_times;
        bool found = false;
        std::vector<vertex_descriptor> predecessors(num_vertices(g));
        std::vector<double> distances(num_vertices(g));
        try {
            dijkstra_shortest_paths(
                g,
                source,
                weight_map(get(&Edge_Property::length, g)).
                predecessor_map(&predecessors[0]).
                distance_map(&distances[0]).
                visitor(one_to_one_distance_visitor(target))
            );
        } catch (found_goals& goal) {
            //std::cout << "Found goals" << '\n';
            found = true;
        }
        if (found) {
            return distances[target];
        } else {
            return DIST_NOT_FOUND;
        };
    };
    /**
     *  Return a shortest path from source to target as a vector of
     *  edge ids. If no path is found, an empty vector is returned.
     *
     */
    std::vector<int> single_source_target_path(int source, int target) {
        ++calling_times;
        bool found = false;
        std::vector<vertex_descriptor> predecessors(num_vertices(g));
        std::vector<double> distances(num_vertices(g));
        try {
            dijkstra_shortest_paths(
                g,
                source,
                weight_map(get(&Edge_Property::length, g)).
                predecessor_map(&predecessors[0]).
                distance_map(&distances[0]).
                visitor(
                    one_to_one_distance_visitor(target)
                )
            );
        } catch (found_goals& goal) {
            //std::cout << "Found goals" << '\n';
            found = true;
        }
        if (found) {
            // Return the sp path from the result
            std::vector<int> path;
            int current_node = target;
            while (current_node != source) {
                double cost = distances[current_node] - distances[predecessors[current_node]];
                int edge_id = get_edge_id(predecessors[current_node], current_node, cost);
                path.push_back(edge_id);
                current_node = predecessors[current_node];
            }
            std::reverse(path.begin(), path.end());
            return path;
        } else {
            return std::vector<int>();
        };
    };
    /**
     * Find the routing with the first and last node
     */
    bool single_source_target_with_first_prev_node(int source, int target,int *first_n,int *prev_n,double *cost) {
        bool found = false;
        std::vector<vertex_descriptor> predecessors(num_vertices(g));
        std::vector<double> distances(num_vertices(g));
        try {
            dijkstra_shortest_paths(
                g,
                source,
                weight_map(get(&Edge_Property::length, g)).
                predecessor_map(&predecessors[0]).
                distance_map(&distances[0]).
                visitor(
                    one_to_one_distance_visitor(target)
                )
            );
        } catch (found_goals& goal) {
            //std::cout << "Found goals" << '\n';
            found = true;
        }
        if (found) {
            // Return the sp path from the result
            int current_node = target;
            *prev_n =predecessors[target];
            while (current_node != source) {
                *first_n = current_node;
                current_node = predecessors[current_node];
            }
            *cost = distances[target];
        } else {
            *prev_n = -1;
            *first_n = -1;
            *cost = DIST_NOT_FOUND;
        };
        return found;
    };
    long int get_number_queries(){
        return calling_times;
    };
    C_Path *construct_complete_path_routing(O_Path *path)
    {
        if (path==nullptr) return nullptr;
        C_Path *edges= new C_Path();
        int N = path->size();
        edges->push_back((*path)[0]->edge->id);
        for(int i=0; i<N-1; ++i)
        {
            Candidate* a = (*path)[i];
            Candidate* b = (*path)[i+1];
            if ((a->edge->id!=b->edge->id) || (a->offset>b->offset))
            {
                auto segs = single_source_target_path(a->edge->target,b->edge->source);
                // No path exist.
                if (segs.empty() &&  a->edge->target!=b->edge->source)
                {
                    delete edges; // free the memory of edges
                    return nullptr;
                }
                for (int e:segs)
                {
                    edges->push_back(e);
                }
                edges->push_back(b->edge->id);
            }
        }
        return edges;
    };
private:
    /* Type definition for property stored at each edge */
    struct Edge_Property
    {
        int id;
        double length;
    };
    // No vertex property, but has edge property
    typedef boost::adjacency_list <boost::vecS, boost::vecS, boost::directedS, boost::no_property, Edge_Property> Graph_T; // graph type
    typedef Graph_T::vertex_descriptor vertex_descriptor;
    typedef Graph_T::edge_descriptor edge_descriptor;
    typedef boost::graph_traits<Graph_T>::vertex_iterator vertex_iterator;
    typedef boost::graph_traits<Graph_T>::out_edge_iterator out_edge_iterator;
    struct found_goals {}; // Used for driving distances
    /**
     *  This visitor is used for finding the shortest path
     *  distance from a single source to single target.
     */
    class one_to_one_distance_visitor : public boost::default_dijkstra_visitor {
    public:
        /**
         *  The distances field is also passed to the graph as a distance map
         *  that gets updated outside of the visitor class.
         */
        explicit one_to_one_distance_visitor(
            vertex_descriptor V
        ) : m_V(V) {};
        template <class Graph>void examine_vertex(vertex_descriptor u, Graph &g) {
            // Reach V in the routing process
            if (u == m_V) throw found_goals();
        };
    private:
        vertex_descriptor m_V; // target node
    };
    /*
    class one_to_many_visitor : public boost::default_dijkstra_visitor {
    public:
        explicit one_to_many_visitor(std::vector<vertex_descriptor> goals)
            : m_goals(goals.begin(), goals.end()) {}
        template <class Graph>
        void examine_vertex(vertex_descriptor u, Graph &g) {
            auto s_it = m_goals.find(u);
            if (s_it == m_goals.end()) return;
            // we found one more goal
            m_goals.erase(s_it);
            // We have found all goals
            if (m_goals.size() == 0) throw found_goals();
        }
    private:
        std::set<vertex_descriptor> m_goals;
    };
    */
    /**
     * The visitor is a class whose function examine_vertex() is called
     * whenever a new node is checked in conventional Dijkstra
     * algorithm.
     *
     * It is called in the driving distance function.
     */
    class driving_distance_visitor : public boost::default_dijkstra_visitor {
    public:
        /**
         *  The distances field is also passed to the graph as a distance map
         *  that gets updated outside of the visitor class.
         */
        explicit driving_distance_visitor(
            double distance_goal,
            std::deque< vertex_descriptor > &nodesInDistance,
            std::vector< double > &distances
        ) : m_distance_goal(distance_goal), m_nodes(nodesInDistance), m_dist(distances) {};
        template <class Graph>void examine_vertex(vertex_descriptor u, Graph &g) {
            m_nodes.push_back(u);
            if (m_dist[u] > m_distance_goal) {
                m_nodes.pop_back();
                throw found_goals();
            }
        };
    private:
        double m_distance_goal; //Delta
        std::deque< vertex_descriptor > &m_nodes; //Precedessors
        std::vector< double > &m_dist; // Distances
    }; // driving_distance_visitor
    /*  Public members and methods */
    // NetworkGraphConfig config;
    Graph_T g;
    int get_edge_id(vertex_descriptor source, vertex_descriptor target, double cost) {
        edge_descriptor e;
        out_edge_iterator out_i, out_end;
        for (boost::tie(out_i, out_end) = boost::out_edges(source, g);
                out_i != out_end; ++out_i) {
            e = *out_i; // Can we directly get edge id here or latter from the graph
            if (target == boost::target(e, g) && (g[e].length - cost <= DOUBLE_MIN)) {
                return  g[e].id;
            }
        }
        std::cout << "Edge not found for source " << source << " target " << target
                  << " cost " << cost << '\n';
        return -1;
    };
    std::vector<vertex_descriptor> get_successors(std::deque<vertex_descriptor> &nodesInDistance, std::vector<vertex_descriptor>& predecessors) {
        int N = nodesInDistance.size();
        std::vector<vertex_descriptor> successors = std::vector<vertex_descriptor>(N);
        int i;
        vertex_descriptor u, v;
        vertex_descriptor source = nodesInDistance[0];// source node
        for (i = 0; i < N; ++i) {
            v = nodesInDistance[i];
            while ((u = predecessors[v]) != source) {
                v = u;
            }
            successors[i] = v;
        }
        return successors;
    };
    // The reason that template is used here as we want to write to both std or to a file
    void driving_distance(const vertex_descriptor& source, double delta, std::ostream& stream) {
        if (source % 5000 == 0) {
            std::cout << "Progress source " << source << '\n';
        }
        // std::cout << "Progress source " << source << '\n';
        std::vector<vertex_descriptor> predecessors(num_vertices(g));
        // a list of costs stored for one node to all nodes in the graph
        std::vector<double> distances(num_vertices(g));
        std::deque<vertex_descriptor> nodesInDistance;

        // std::cout << "First value of predecessors is " << *(predecessors.begin()) << '\n';
        // std::cout << "First value of distance is " << *(distances.begin()) << '\n';
        // http://www.boost.org/doc/libs/1_61_0/libs/graph/doc/dijkstra_shortest_paths.html

        try {
            dijkstra_shortest_paths(
                g,
                source,
                weight_map(get(&Edge_Property::length, g)).
                predecessor_map(&predecessors[0]).
                distance_map(&distances[0]).
                visitor(
                    driving_distance_visitor(
                        delta, nodesInDistance, distances
                    )
                )
            );
        } catch (found_goals& goal) {
            //std::cout << "Found goals" << '\n';
        }

        // Get successors for each node reached
        std::vector<vertex_descriptor> successors =
            get_successors(nodesInDistance, predecessors);
        double cost;
        int edge_id;
        int k = 0;
        vertex_descriptor node;
        while (k < nodesInDistance.size()) {
            node = nodesInDistance[k];
            if (source != node) {
                // The cost is need to identify the edge ID
                cost = distances[successors[k]] - distances[source];
                edge_id = get_edge_id(source, successors[k], cost);
                stream << source << ";" << node << ";" << successors[k] << ";"
                       << predecessors[node] << ";" << edge_id << ";" << distances[node]
                       << "\n";
            }
            ++k;
        }

    };
    long int calling_times = 0;
    // const static int BUFFER_LINE = 1024;
    static constexpr double DOUBLE_MIN = 1.e-6; // This is used for comparing double values
}; // NetworkGraph
}
#endif /* MM_NETWORK_GRAPH_HPP */

max_stars_repo_name: BeichuanH/fmm

max_issues_repo_name: BeichuanH/fmm

max_forks_repo_name: BeichuanH/fmm


text:
/*!
@file
Defines `boost::hana::Product::mcd`.

@copyright Louis Dionne 2014
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
 */

#ifndef BOOST_HANA_PRODUCT_MCD_HPP
#define BOOST_HANA_PRODUCT_MCD_HPP

#include <boost/hana/product/product.hpp>

#include <boost/hana/comparable/equal_mcd.hpp>
#include <boost/hana/core/is_a.hpp>
#include <boost/hana/logical/logical.hpp>

namespace boost { namespace hana {
    //! Minimal complete definition: `first` and `second`
    struct Product::mcd { };

    //! Instance of `Comparable` for `Product`s.
    //!
    //! Two products `x` and `y` are equal iff they are equal element-wise,
    //! i.e. iff
    //! @code
    //!     first(x) == first(y) && second(x) == second(y)
    //! @endcode
    //!
    //! ### Example
    //! @snippet example/product/comparable.cpp main
    template <typename T, typename U>
    struct Comparable::instance<T, U, when<
        is_a<Product, T>() && is_a<Product, U>()
    >> : Comparable::equal_mcd {
        template <typename X, typename Y>
        static constexpr auto equal_impl(X x, Y y) {
            return and_(
                equal(first(x), first(y)),
                equal(second(x), second(y))
            );
        }
    };

#if 0
    template <typename T>
    struct Functor::instance<T, when<is_a<Pair, T>()>>
        : Functor::fmap_mcd
    {
        template <typename F, typename P>
        static constexpr auto fmap_impl(F f, P p)
        { return pair(f(first(p)), f(second(p))); }
    };

    template <typename T>
    struct Applicative::instance<T, when<is_a<Pair, T>()>>
        : Applicative::mcd
    {
        template <typename X>
        static constexpr auto lift_impl(X x)
        { return pair(x, x); }

        template <typename F, typename P>
        static constexpr auto ap_impl(F f, P p)
        { return pair(first(f)(first(p), second(f)(second(p)))); }
    };

    template <typename T>
    struct Monad::instance<T, when<is_a<Pair, T>()>>
        : Monad::bind_mcd<T>
    {
        template <typename P, typename F>
        static constexpr auto bind_impl(P p, F f) {
            return pair(
                bind(first(p), compose(first, f)),
                bind(second(p), compose(second, f))
            );
        }
    };

    template <typename T>
    struct Foldable::instance<T, when<is_a<Pair, T>()>>
        : Foldable::mcd
    {
        template <typename P, typename S, typename F>
        static constexpr auto foldr_impl(P p, S s, F f) {
            return f(first(p), f(second(p), s));
        }

        template <typename P, typename S, typename F>
        static constexpr auto foldl_impl(P p, S s, F f) {
            return f(f(s, first(p)), second(p));
        }
    };
#endif
}} // end namespace boost::hana

#endif // !BOOST_HANA_PRODUCT_MCD_HPP

ext: hpp

max_stars_repo_name: rbock/hana

max_issues_repo_name: rbock/hana

max_forks_repo_name: rbock/hana


text:
/*
* Copyright (C) 2014-2017 Rhonda Software.
* All rights reserved.
*/

//////////////////////////////////////////////////////////////////////////

#include "GeneratorOptions.h"
#include "RpcApiInterface.h"
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
#include <cassert>

//////////////////////////////////////////////////////////////////////////
namespace po = boost::program_options;

namespace
{
    // list of default constants
    const fs::path defaultOutputFoldef("./");
    const fs::path defaultConfigTemplate("./config.xml.in");
    const std::string defaultConfigName = "generator-config.xml";
    const std::string defaultApiCfile = "api.c";
    const std::string defaultTargets = "all";
    const std::string defaultCC = "gcc";
    const bool defaultUseAbsolutePaths = false;

    po::options_description desc{ "Options" };
}

//////////////////////////////////////////////////////////////////////////
GOptions::GOptions()
    : mode(EGeneratorMode::help)
    , outFolder(defaultOutputFoldef)
    , configTemplate(defaultConfigTemplate)
    , configName(defaultConfigName)
    , apiCfile(defaultApiCfile)
    , targets(defaultTargets)
    , cc(defaultCC)
    , absolutePaths(defaultUseAbsolutePaths)
{

}

//////////////////////////////////////////////////////////////////////////
void to_cout(const std::vector<std::string> &v)
{
    std::copy(v.begin(), v.end(), std::ostream_iterator<std::string>{std::cout, "\n"});
}

GOptions::EGeneratorMode GOptions::ParseOptions(int ac, const char** av)
{
    desc.add_options()
        ("help,h", "Display this information.")
        ("targets,t", po::value<std::string>(), ("Comma separated list of targets(\"CPP,C,SVR\" etc.) (default = \"" + defaultTargets + "\").").c_str())
        ("configure,c", po::value<std::vector<fs::path>>()->multitoken(), "Space separated list of INI files. INI files provided by Camera SDK or Platform project with path (absolute or related from current folder).")
        ("outxml", po::value<std::string>(), ("Output configuration file name(w / o path) for generating phase(default = \"" + defaultConfigName + "\").").c_str())
        ("outc", po::value<std::string>(), ("Output configuration file name (w/o path) for code analyzer (default = \"" + defaultApiCfile + "\").").c_str())
        ("inxml", po::value<fs::path>(), ("Input template configuration file with path (default = \"" + defaultConfigTemplate.generic_string() + "\").").c_str())
        ("outdir", po::value<fs::path>(), ("Absolute/relative path to output files (default = \"" + defaultOutputFoldef.generic_string() + "\").").c_str())
        ("fullpath", "Generate absolute paths in output files.")
        ("complete", "Full cycle of generating: configure, castxml, generating.")
        ("cc", po::value<std::string>(), ("Compiler name for using from castxml (default = \"" + defaultCC + "\").").c_str());

    po::options_description desc_hidden{ "Hidden options" };
    desc_hidden.add_options()
        ("configname", po::value<std::string>()->zero_tokens());

    po::positional_options_description pos_desc;
    pos_desc.add("configname", 1);

    po::options_description cmdline_options;
    cmdline_options.add(desc).add(desc_hidden);

    po::command_line_parser parser{ ac, av };
    parser.options(cmdline_options).positional(pos_desc).allow_unregistered().style(po::command_line_style::default_style | po::command_line_style::allow_slash_for_short);
    po::parsed_options parsed_options = parser.run();

    po::variables_map vm;
    try
    {
        po::store(parsed_options, vm);
        po::notify(vm);
    }
    catch (const po::error& e)
    {
        STG_EXCEPTION_ERROR(GMSG << e.what());
    }

    if (vm.count("help"))
    {
        mode = EGeneratorMode::help;
    }
    else
    {
        if (vm.count("complete"))
        {
            mode = EGeneratorMode::complete;
        }

        if (vm.count("configname"))
        {
            if (mode != EGeneratorMode::complete)
            {
                configName = vm["configname"].as<std::string>();
                mode = EGeneratorMode::generate;
            }
        }

        if (vm.count("configure"))
        {
            if (mode != EGeneratorMode::generate)
            {
                iniList = vm["configure"].as<std::vector<fs::path>>();
                if (mode != EGeneratorMode::complete)
                {
                    mode = EGeneratorMode::configure;
                }
            }
        }

        if (vm.count("targets"))
        {
            if (mode == EGeneratorMode::generate || mode == EGeneratorMode::complete)
            {
                targets = vm["targets"].as<std::string>();
            }
        }

        if (vm.count("outxml"))
        {
            if (mode == EGeneratorMode::configure || mode == EGeneratorMode::complete)
            {
                configName = vm["outxml"].as<std::string>();
            }
        }

        if (vm.count("outc"))
        {
            if (mode == EGeneratorMode::configure || mode == EGeneratorMode::complete)
            {
                apiCfile = vm["outc"].as<std::string>();
            }
        }

        if (vm.count("inxml"))
        {
            if (mode == EGeneratorMode::configure || mode == EGeneratorMode::complete)
            {
                configTemplate = vm["inxml"].as<fs::path>();
            }
        }

        if (vm.count("outdir"))
        {
            if (mode == EGeneratorMode::configure || mode == EGeneratorMode::complete)
            {
                outFolder = vm["outdir"].as<fs::path>();
            }
        }

        if (vm.count("fullpath"))
        {
            if (mode == EGeneratorMode::configure || mode == EGeneratorMode::complete)
            {
                absolutePaths = true;
            }
        }

        if (vm.count("cc"))
        {
            if (mode == EGeneratorMode::configure || mode == EGeneratorMode::complete)
            {
                cc = vm["cc"].as<std::string>();
            }
        }
    }

    if ((mode == EGeneratorMode::configure || mode == EGeneratorMode::complete) && iniList.empty())
    {
        STG_EXCEPTION_ERROR("No INI files are defined.");
    }

    VerifyParameters();

    return mode;
}

//////////////////////////////////////////////////////////////////////////
void GOptions::VerifyParameters()
{
    switch (mode)
    {
    case EGeneratorMode::help:
        break;
    case EGeneratorMode::generate:
        CheckConfigureFileExists();
        break;
    case EGeneratorMode::complete:
    case EGeneratorMode::configure:
        CheckConfigureTemplateExists();
        CheckINIfilesExists();
        break;
    default:
        STG_EXCEPTION_ERROR("unexpected mode");
    }
}

//////////////////////////////////////////////////////////////////////////
void GOptions::CheckConfigureFileExists()
{
    fs::path cfg(configName);
    if (!fs::exists(cfg))
    {
        cfg = outFolder / cfg;
        if (fs::exists(cfg))
        {
            configName = cfg.string();
            boost::algorithm::replace_all(configName, "\\", "/");
        }
        else
        {
            STG_EXCEPTION_ERROR(GMSG << "Configure file \"" << configName << "\" was not found");
        }
    }
}

//////////////////////////////////////////////////////////////////////////
void GOptions::CheckConfigureTemplateExists()
{
    if (fs::exists(configTemplate))
    {
        if (!configTemplate.is_absolute())
        {
            configTemplate = fs::absolute(configTemplate);
        }
    }
    else
    {
        STG_EXCEPTION_ERROR(GMSG << "Configure template file \"" << configTemplate << "\" was not found");
    }
}

//////////////////////////////////////////////////////////////////////////
void GOptions::CheckINIfilesExists()
{
    for (fs::path& ini : iniList)
    {
        if (fs::exists(ini))
        {
            if (!ini.is_absolute())
            {
                ini = fs::absolute(ini);
            }
        }
        else
        {
            STG_EXCEPTION_ERROR(GMSG << "INI file \"" << ini << "\" was not found");
        }
    }
}

//////////////////////////////////////////////////////////////////////////
void GOptions::PrintUsage()
{
    std::cout <<
        "Usage: ipcgen [<configuration-file-name>] [OPTIONS]\n";
    std::cout << desc << std::endl;
    std::cout <<
        "  <configuration-file-name> XML file contains configuration data.\n"
        "                            this file is output from configure phase (option --outxml).\n"
        "\n"
        "There is defined 4 work modes.\n"
        "1. Help mode:\n"
        "  ipcgen --help\n"
        "    Display help screen.\n\n"
        "2. Configure mode:\n"
        "  ipcgen --configure <INI-file> [[INI-file]...] [--outxml <config-xml>] [--outc <api-c>] [--inxml <config-in>] [--outdir <path>] [--fullpath true | false]\n"
        "    Generate configure files.\n\n"
        "3. Generating wrappers mode:\n"
        "  ipcgen [<configuration-file-name>] [--targets <list>]\n"
        "    Generating wrappers for targets platform.\n\n"
        "4. Execute all stages generating.\n"
        "  ipcgen --complete [OPTIONS]\n"
        "   Execute all stages: configure, castxml, generating.\n\n";
}

ext: cpp

max_stars_repo_name: dshadrin/RpcWrappersGenerator

max_issues_repo_name: dshadrin/RpcWrappersGenerator

max_forks_repo_name: dshadrin/RpcWrappersGenerator


text:
// -*- coding: utf-8 -*-
// Copyright (C) 2016 MUJIN Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <boost/thread.hpp> // for sleep
#include <boost/property_tree/ptree.hpp>
#include "testmujincontrollerclient/mock_binpickingtask.h"

#ifdef MUJIN_USEZMQ
#endif

#ifdef _WIN32
#include <float.h>
#define isnan _isnan
#endif

#include <cmath>

#include "logging.h"

MUJIN_LOGGER("mujin.testcontrollerclientcpp.mock_binpickingtask");

namespace mujinclient {

} // end namespace mujinclient

max_stars_repo_name: mujin/testcontrollerclientcpp

max_issues_repo_name: mujin/testcontrollerclientcpp

max_forks_repo_name: mujin/testcontrollerclientcpp


text:
//
// Created by GXSN-Pro on 2018/1/3.
//

#include <tuple>
#include "tile_id.hpp"
#include <boost/functional/hash.hpp>

namespace OpenEarth {
    namespace Tile {
        bool TileID::operator==(const TileID &rhs) const {
            return x == rhs.x && y == rhs.y && z == rhs.z;
        }

        bool TileID::operator!=(const TileID &rhs) const {
            return x != rhs.x || y != rhs.y || z != rhs.z;
        }

        bool TileID::operator<(const TileID &rhs) const {
            return std::tie(z, x, y) < std::tie(rhs.z, rhs.x, rhs.y);
        }

        bool TileID::isChildOf(const TileID &rhs) const {
            return false;
        }

    }
}

size_t std::hash<OpenEarth::Tile::TileID>::operator()(const OpenEarth::Tile::TileID &id)const {
    size_t seed;
    boost::hash_combine(seed,id.z);
    boost::hash_combine(seed,id.x);
    boost::hash_combine(seed,id.y);
    return seed;
}


text:
#include "testsuite.h"
#include <blitz/array.h>

BZ_USING_NAMESPACE(blitz)

int main()
{
  {
    Array<int, 2> A(7,11, contiguousArray);
    BZTEST(A.isStorageContiguous());

    BZTEST(!(A(Range(fromStart, toEnd, 2),
        Range::all())).isStorageContiguous());
    BZTEST(A.reverse(firstDim).isStorageContiguous());
    BZTEST(A.reverse(secondDim).isStorageContiguous());
    BZTEST(!A(Range::all(), 4).isStorageContiguous());
    BZTEST(A(4, Range::all()).isStorageContiguous());
  }

  {
    Array<int, 2> A(7,11, ColumnMajorArray<2>(contiguousData));
    BZTEST(A.isStorageContiguous());

    BZTEST(!(A(Range(fromStart, toEnd, 2),
        Range::all())).isStorageContiguous());
    BZTEST(A.reverse(firstDim).isStorageContiguous());
    BZTEST(A.reverse(secondDim).isStorageContiguous());
    BZTEST(A(Range::all(), 4).isStorageContiguous());
    BZTEST(!A(4, Range::all()).isStorageContiguous());
  }

  {
    Array<int, 2> A(Range(-4,8),Range(4,27), contiguousArray);
    BZTEST(A.isStorageContiguous());

    BZTEST(!(A(Range(fromStart, toEnd, 2),
        Range::all())).isStorageContiguous());
    BZTEST(A.reverse(firstDim).isStorageContiguous());
    BZTEST(A.reverse(secondDim).isStorageContiguous());
    BZTEST(!A(Range::all(), 4).isStorageContiguous());
    BZTEST(A(4, Range::all()).isStorageContiguous());
  }
}

max_stars_repo_name: fraguela/depspawn

max_issues_repo_name: MSV-Project/IBAMR

max_forks_repo_name: MSV-Project/IBAMR


text:
#define BOOST_TEST_MODULE pcraster geo gridded_points
#include <boost/test/unit_test.hpp>
#include "geo_griddedpoints.h"
#include "geo_rasterspace.h"
#include "geo_point.h"

BOOST_AUTO_TEST_CASE(constructor)
{
  using namespace geo;

  RasterSpace space(5, 6, 10.0, 0.0, 1.0, YIncrB2T);
  GriddedPoints<Point<double, 2> > points(space);
  // BOOST_CHECK(false);
}

BOOST_AUTO_TEST_CASE(nr_points)
{
  using namespace geo;

  // Raster with one row and two columns.
  RasterSpace space(1, 2, 1.0, 0.0, 0.0, YIncrB2T);
  GriddedPoints<Point<double, 2> > points(space);

  BOOST_CHECK(points.nrPoints(0, 0) == 0);
  BOOST_CHECK(points.nrPoints(0, 1) == 0);

  // First cell is MV. Second not.
  points.setMV(0, 0);

  Point<double, 2> p;
  p[0] = 1.0;
  p[1] = 0.0;

  points.insert(p);
  points.insert(p);
  points.insert(p);

  BOOST_CHECK(points.nrPoints(0, 0) == 0);
  BOOST_CHECK(points.nrPoints(0, 1) == 3);
}

BOOST_AUTO_TEST_CASE(points)
{
  using namespace geo;

  std::vector<Point<double, 2> > points;

  {
    RasterSpace space(1, 1, 1.0, 0.0, 0.0, YIncrB2T);
    GriddedPoints<Point<double, 2> > griddedPoints(space);

    points.clear();
    griddedPoints.points(CellLoc(0, 0), 3, points);
    BOOST_CHECK(points.empty());

    griddedPoints.insert(Point<double, 2>(0.0, 0.0));
    points.clear();
    griddedPoints.points(CellLoc(0, 0), 1, points);
    BOOST_CHECK(points.size() == 1);

    points.clear();
    griddedPoints.points(CellLoc(0, 0), 3, points);
    BOOST_CHECK(points.size() == 1);

    griddedPoints.insert(Point<double, 2>(0.0, 0.0));
    points.clear();
    griddedPoints.points(CellLoc(0, 0), 1, points);
    BOOST_CHECK(points.size() == 2);

    points.clear();
    griddedPoints.points(CellLoc(0, 0), 3, points);
    BOOST_CHECK(points.size() == 2);
  }

  {
    RasterSpace space(3, 3, 1.0, 0.0, 0.0, YIncrT2B);
    GriddedPoints<Point<double, 2> > griddedPoints(space);

    points.clear();
    griddedPoints.points(CellLoc(0, 0), 1, points);
    BOOST_CHECK(points.empty());

    // Put a point in each cell.
    for(size_t row = 0; row < griddedPoints.nrRows(); ++row) {
      for(size_t col = 0; col < griddedPoints.nrCols(); ++col) {
        griddedPoints.insert(
              Point<double, 2>(row * 1.0, col * 1.0));
      }
    }

    // 5 points in a circular neighbourhood with radius 1.
    points.clear();
    griddedPoints.points(CellLoc(1, 1), 1, points);
    BOOST_CHECK(points.size() == 5);
  }
}

BOOST_AUTO_TEST_CASE(copy)
{
  using namespace geo;

  // Create and fill an object.
    RasterSpace space(3, 3, 1.0, 0.0, 0.0, YIncrT2B);
    GriddedPoints<Point<double, 2> > source(space);
    for(size_t row = 0; row < source.nrRows(); ++row) {
      for(size_t col = 0; col < source.nrCols(); ++col) {
        source.insert(Point<double, 2>(row * 1.0, col * 1.0));
      }
    }

  // Create a copy.
    GriddedPoints<Point<double, 2> > target(source);

  // Compare source and target objects.
    BOOST_CHECK(source.size() == target.size());
}

ext: cc

max_stars_repo_name: quanpands/wflow

max_issues_repo_name: quanpands/wflow

max_forks_repo_name: quanpands/wflow