Program Listing for File Semirings.hpp

Return to documentation for file (include/networkit/algebraic/Semirings.hpp)

/*
 * Semirings.hpp
 *
 *  Created on: May 31, 2016
 *      Author: Michael Wegner (michael.wegner@student.kit.edu)
 */

#ifndef NETWORKIT_ALGEBRAIC_SEMIRINGS_HPP_
#define NETWORKIT_ALGEBRAIC_SEMIRINGS_HPP_

#include <algorithm>

// *****************************************************
//                  Semiring Definitions
// *****************************************************

class ArithmeticSemiring final {
public:
    ArithmeticSemiring() = default;
    ~ArithmeticSemiring() = default;

    inline static double add(double a, double b) { return a + b; }

    inline static double mult(double a, double b) { return a * b; }

    inline static double zero() { return 0; };

    inline static double one() { return 1; };
};

class MinPlusSemiring final {
public:
    MinPlusSemiring() = default;
    ~MinPlusSemiring() = default;

    inline static double add(double a, double b) { return std::min(a, b); }

    inline static double mult(double a, double b) { return a + b; }

    inline static double zero() { return std::numeric_limits<double>::infinity(); };

    inline static double one() { return 0; };
};

class MaxPlusSemiring final {
public:
    MaxPlusSemiring() = default;
    ~MaxPlusSemiring() = default;

    inline static double add(double a, double b) { return std::max(a, b); }

    inline static double mult(double a, double b) { return a + b; }

    inline static double zero() { return -std::numeric_limits<double>::infinity(); };

    inline static double one() { return 0; };
};

class MinMaxSemiring final {
public:
    MinMaxSemiring() = default;
    ~MinMaxSemiring() = default;

    inline static double add(double a, double b) { return std::min(a, b); }

    inline static double mult(double a, double b) { return std::max(a, b); }

    inline static double zero() { return std::numeric_limits<double>::infinity(); };

    inline static double one() { return -std::numeric_limits<double>::infinity(); };
};

class MaxMinSemiring final {
public:
    MaxMinSemiring() = default;
    ~MaxMinSemiring() = default;

    inline static double add(double a, double b) { return std::max(a, b); }

    inline static double mult(double a, double b) { return std::min(a, b); }

    inline static double zero() { return -std::numeric_limits<double>::infinity(); };

    inline static double one() { return 0; };
};

class IntLogicalSemiring final {
public:
    IntLogicalSemiring() = default;
    ~IntLogicalSemiring() = default;

    inline static double add(double a, double b) { return (int)a || (int)b; }

    inline static double mult(double a, double b) { return (int)a && (int)b; }

    inline static double zero() { return 0; };

    inline static double one() { return 1; };
};

class GaloisFieldSemiring final {
public:
    GaloisFieldSemiring() = default;
    ~GaloisFieldSemiring() = default;

    inline static double add(double a, double b) { return (int)a ^ (int)b; }

    inline static double mult(double a, double b) { return (int)a & (int)b; }

    inline static double zero() { return 0; };

    inline static double one() { return 1; };
};

#endif // NETWORKIT_ALGEBRAIC_SEMIRINGS_HPP_