.. _program_listing_file_include_support_utils.h: Program Listing for File utils.h ================================ |exhale_lsh| :ref:`Return to documentation for file ` (``include/support/utils.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* ############################################# * This file is part of * ZERO * * Copyright (c) 2020 * Released under the Creative Commons * CC BY-NC-SA 4.0 License * * Find out more at * https://github.com/ds4dm/ZERO * #############################################*/ #pragma once #include "coin/CoinPackedMatrix.hpp" #include "coin/CoinPackedVector.hpp" #include "zero.h" #include #include #include #include namespace Utils { arma::mat resizePatch(const arma::mat &mat, const unsigned int nR, const unsigned int nC); arma::vec resizePatch(const arma::vec &mat, const unsigned int nR); bool containsRow(const arma::sp_mat &A, const arma::vec &row, const double tol = 1e-6); bool containsElement(const arma::vec &b, const double &element, const double tol = 1e-6); bool containsConstraint(const arma::sp_mat &A, const arma::vec & b, const arma::vec & lhs, const double & rhs, const double tol = 1e-6); bool containsConstraint(const arma::sp_mat &A, const arma::vec & b, const arma::sp_mat &lhs, const double & rhs, const double tol = 1e-6); // Saving and retrieving an arma::vec void appendSave(const arma::vec & matrix, const std::string &out, const std::string &header = "", bool erase = false); long int appendRead(arma::vec & matrix, const std::string &in, long int pos, const std::string &header = ""); // Saving and retrieving an arma::sp_mat void appendSave(const arma::sp_mat &matrix, const std::string & out, const std::string & header = "", bool erase = false); long int appendRead(arma::sp_mat & matrix, const std::string &in, long int pos, const std::string &header = ""); // Saving and retrieving an std::vector void appendSave(const std::vector v, const std::string out, const std::string header = "", bool erase = false); long int appendRead(std::vector &v, const std::string in, long int pos, const std::string header = ""); // Saving std::string void appendSave(const std::string &v, const std::string &out, bool erase = false); long int appendRead(std::string &v, const std::string &in, long int pos); // Saving A long int void appendSave(const long int v, const std::string &out, const std::string &header = "", bool erase = false); long int appendRead(long int &v, const std::string &in, long int pos, const std::string &header = ""); // Saving A unsigned int void appendSave(const unsigned int v, const std::string &out, const std::string &header = "", bool erase = false); long int appendRead(unsigned int &v, const std::string &in, long int pos, const std::string &header = ""); bool isZero(const arma::mat &M, double tol = 1e-6) noexcept; bool isZero(const arma::sp_mat &M, double tol = 1e-6) noexcept; void sortByKey(perps &P); VariableBounds intersectBounds(const VariableBounds &bA, const VariableBounds &bB); CoinPackedMatrix armaToCoinSparse(const arma::sp_mat &A); std::vector armaToCoinPackedVector(const arma::sp_mat &A); std::string printBounds(const VariableBounds &bounds); arma::vec normalizeVec(const arma::vec &v); void normalizeIneq(arma::vec &lhs, double &rhs, bool force); double round_nplaces(const double &value, const int &numDecimals = 5); void addSparseConstraints(const arma::sp_mat &A, const arma::vec & b, GRBVar * x, const std::string & basename, GRBModel * model, int sense, GRBVar * z); arma::sp_mat resizePatch(const arma::sp_mat &mat, const unsigned int nR, const unsigned int nC); int vecToBin(const arma::vec &x); int nonzeroDecimals(const double num, const int decimalBound = 6); bool isEqualAbs(const double a, const double b, const double tol = 1e-6); bool isEqualRel(const double a, const double b, const double percent = (1 - 1e-4)); bool isEqual(const double a, const double b, const double tol = 1e-6, const double percent = (1 - 1e-4)); arma::sp_mat clearMatrix(const arma::sp_mat &A, double tol=1e-6, double percent=1-1e-6); arma::vec clearVector(const arma::vec &b, double tol=1e-6, double percent=1-1e-6); int getSign(double val); } // namespace Utils // namespace Utils