Scippy

    SCIP

    Solving Constraint Integer Programs

    multiprecision.hpp
    Go to the documentation of this file.
    1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    2/* */
    3/* This file is part of the program and library */
    4/* SCIP --- Solving Constraint Integer Programs */
    5/* */
    6/* Copyright (c) 2002-2025 Zuse Institute Berlin (ZIB) */
    7/* */
    8/* Licensed under the Apache License, Version 2.0 (the "License"); */
    9/* you may not use this file except in compliance with the License. */
    10/* You may obtain a copy of the License at */
    11/* */
    12/* http://www.apache.org/licenses/LICENSE-2.0 */
    13/* */
    14/* Unless required by applicable law or agreed to in writing, software */
    15/* distributed under the License is distributed on an "AS IS" BASIS, */
    16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
    17/* See the License for the specific language governing permissions and */
    18/* limitations under the License. */
    19/* */
    20/* You should have received a copy of the Apache-2.0 license */
    21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
    22/* */
    23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    24
    25/**@file struct_rational.h
    26 * @brief definition of wrapper class for rational numbers
    27 * @author Leon Eifler
    28 */
    29
    30/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    31
    32#ifndef __SCIP_MULTIPRECISION_HPP_
    33#define __SCIP_MULTIPRECISION_HPP_
    34
    35#include <numeric>
    36#include <vector>
    37#include <string>
    38
    39#ifdef SCIP_WITH_BOOST
    40#include <boost/multiprecision/number.hpp>
    41
    42#ifdef SCIP_WITH_GMP
    43#include <boost/multiprecision/gmp.hpp>
    44using namespace boost::multiprecision;
    45namespace scip
    46{
    47 using Rational = boost::multiprecision::number<gmp_rational, et_off>;
    48 using Integer = number<gmp_int, et_off>;
    49}
    50#else
    51#include <boost/multiprecision/cpp_int.hpp>
    52using namespace boost::multiprecision;
    53namespace scip
    54{
    55 using Rational = cpp_rational;
    56 using Integer = cpp_int;
    57}
    58#endif
    59
    60namespace scip
    61{
    62 using sparsevec = std::vector<SCIP_RATIONAL>;
    63}
    64#else
    65namespace scip
    66{
    67 /**@todo replace this dummy class with a direct interface to GMP for systems where Boost is not available */
    69 {
    70 public:
    71 double val;
    73 /// copy constructor
    74 Rational(const Rational& r){};
    75 Rational(const char* s){val = atof(s);}
    76 Rational& operator=(const Rational& r){val = 0.0; return *this;};
    77 Rational(const long long num, const long long den){val = 0.0;};
    78 Rational(const Rational& num, const Rational& den){val = 0.0;};
    79 Rational(const std::string& s){val = 0.0;};
    80 Rational(const double d){val = 0.0;};
    81 inline int sign() const { return 0; }
    82 inline bool is_zero() const { return this->val == 0; }
    83 inline std::string str() const { return ""; }
    84 Rational& operator=(const double& r){val = r; return *this;};
    85 Rational& operator=(const int& i){val = i; return *this;};
    86 Rational& operator+(const Rational& r){return *this;};
    87 Rational& operator+(const double& r){return *this;};
    88 Rational& operator-(const Rational& r){return *this;};
    89 Rational& operator-(const double& r){return *this;};
    90 Rational& operator-(){return *this;};
    91 Rational& operator*(const Rational& r){return *this;};
    92 Rational& operator*(const double& r){return *this;};
    93 Rational& operator*=(const double& r){return *this;};
    94 Rational& operator+=(const Rational& r){return *this;};
    95 Rational& operator+=(const double& r){return *this;};
    96 Rational& operator-=(const Rational& r){return *this;};
    97 Rational& operator-=(const double& r){return *this;};
    98 Rational& operator/(const Rational& r){return *this;};
    99 Rational& operator/(const double& r){return *this;};
    100 friend std::ostream& operator<<(std::ostream& os, const Rational& q){return os;};
    101 friend double operator/(const double d, const Rational& r){return 0;};
    102 friend bool operator<(const Rational& r, const double& d){return true;};
    103 friend bool operator<(const Rational& r, const Rational& d){return true;};
    104 friend bool operator>(const Rational& r, const double& d){return true;};
    105 friend bool operator>(const Rational& r, const Rational& d){return true;};
    106 friend bool operator<=(const Rational& r, const double& d){return true;};
    107 friend bool operator<=(const Rational& r, const Rational& d){return true;};
    108 friend bool operator>=(const Rational& r, const double& d){return true;};
    109 friend bool operator>=(const Rational& r, const Rational& d){return true;};
    110 friend bool operator==(const Rational& r, const double& d){return true;};
    111 friend bool operator==(const Rational& r, const Rational& d){return true;};
    112 };
    114 using sparsevec = std::vector<SCIP_RATIONAL>;
    115 Rational& abs(Rational& r){return r;}
    116 Rational& max(Rational& r1, Rational& r2){return r1;}
    117 Rational& min(Rational& r1, Rational& r2){return r1;}
    120}
    121#endif
    122
    123#endif
    SCIP_Real * r
    Definition: circlepacking.c:59
    friend bool operator<(const Rational &r, const Rational &d)
    Rational(const Rational &r)
    copy constructor
    Rational & operator/(const double &r)
    Rational & operator*=(const double &r)
    int sign() const
    friend bool operator==(const Rational &r, const double &d)
    Rational & operator/(const Rational &r)
    Rational(const char *s)
    Rational & operator=(const Rational &r)
    std::string str() const
    Rational & operator*(const double &r)
    Rational & operator-(const double &r)
    friend bool operator>(const Rational &r, const double &d)
    Rational & operator-()
    Rational(const long long num, const long long den)
    Rational & operator-=(const Rational &r)
    Rational & operator=(const double &r)
    friend bool operator>=(const Rational &r, const Rational &d)
    Rational & operator+(const Rational &r)
    friend bool operator<=(const Rational &r, const double &d)
    Rational & operator+(const double &r)
    friend bool operator>=(const Rational &r, const double &d)
    Rational & operator*(const Rational &r)
    Rational & operator=(const int &i)
    Rational(const Rational &num, const Rational &den)
    friend double operator/(const double d, const Rational &r)
    Rational(const double d)
    Rational & operator-=(const double &r)
    friend std::ostream & operator<<(std::ostream &os, const Rational &q)
    friend bool operator<=(const Rational &r, const Rational &d)
    friend bool operator==(const Rational &r, const Rational &d)
    bool is_zero() const
    Rational & operator-(const Rational &r)
    Rational & operator+=(const double &r)
    Rational & operator+=(const Rational &r)
    friend bool operator>(const Rational &r, const Rational &d)
    friend bool operator<(const Rational &r, const double &d)
    Rational(const std::string &s)
    #define SCIP_Longint
    Definition: def.h:141
    Rational Integer
    SCIP_Longint denominator(Rational &r)
    Rational & abs(Rational &r)
    Rational & max(Rational &r1, Rational &r2)
    SCIP_Longint numerator(Rational &r)
    Rational & min(Rational &r1, Rational &r2)
    std::vector< SCIP_RATIONAL > sparsevec