# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1267516057 -3600
# Node ID 1e16e62a9ea12b735e6c63bbd8905bd93f5a1ba9
# Parent e77b621e6e7ecd5a325e1546bdfd51aa01c7b395
Unify the interface of MipSolver and LpSolver (#326)
and improve the documentation.
- Add sol() (without parameters) to MipSolver as an alias for solValue(),
since we had primal() instead of primalValue() in LpSolver.
- Add primalValue() to LpSolver as an alias for primal() (without
parameters).
- Rename ColTypes to ColType in MipSolver and keep the old name as an
obsolete alias (typedef).
- Doc improvements and unifications.
diff --git a/lemon/lp_base.h b/lemon/lp_base.h
|
a
|
b
|
|
| 1790 | 1790 | /// |
| 1791 | 1791 | /// \brief Common base class for LP solvers |
| 1792 | 1792 | /// |
| 1793 | | /// This class is an abstract base class for LP solvers. This class |
| | 1793 | /// This class is an abstract base class for LP solvers. It |
| 1794 | 1794 | /// provides a full interface for set and modify an LP problem, |
| 1795 | 1795 | /// solve it and retrieve the solution. You can use one of the |
| 1796 | 1796 | /// descendants as a concrete implementation, or the \c Lp |
| … |
… |
|
| 1800 | 1800 | class LpSolver : virtual public LpBase { |
| 1801 | 1801 | public: |
| 1802 | 1802 | |
| 1803 | | /// The problem types for primal and dual problems |
| | 1803 | /// \brief The problem types for primal and dual problems |
| | 1804 | /// |
| | 1805 | /// The problem types for primal and dual problems. |
| 1804 | 1806 | enum ProblemType { |
| 1805 | 1807 | /// = 0. Feasible solution hasn't been found (but may exist). |
| 1806 | 1808 | UNDEFINED = 0, |
| … |
… |
|
| 1814 | 1816 | UNBOUNDED = 4 |
| 1815 | 1817 | }; |
| 1816 | 1818 | |
| 1817 | | ///The basis status of variables |
| | 1819 | /// \brief The basis status of variables |
| | 1820 | /// |
| | 1821 | /// The basis status of variables. |
| 1818 | 1822 | enum VarStatus { |
| 1819 | 1823 | /// The variable is in the basis |
| 1820 | 1824 | BASIC, |
| … |
… |
|
| 1857 | 1861 | |
| 1858 | 1862 | ///@{ |
| 1859 | 1863 | |
| 1860 | | ///\e Solve the LP problem at hand |
| | 1864 | ///\brief Solve the specified LP problem |
| 1861 | 1865 | /// |
| | 1866 | ///This function solves the specified LP problem. |
| 1862 | 1867 | ///\return The result of the optimization procedure. Possible |
| 1863 | 1868 | ///values and their meanings can be found in the documentation of |
| 1864 | 1869 | ///\ref SolveExitStatus. |
| … |
… |
|
| 1870 | 1875 | |
| 1871 | 1876 | ///@{ |
| 1872 | 1877 | |
| 1873 | | /// The type of the primal problem |
| | 1878 | /// Return the type of the primal problem |
| | 1879 | |
| | 1880 | /// This function returns the type of the primal problem. |
| | 1881 | /// \see ProblemType |
| 1874 | 1882 | ProblemType primalType() const { |
| 1875 | 1883 | return _getPrimalType(); |
| 1876 | 1884 | } |
| 1877 | 1885 | |
| 1878 | | /// The type of the dual problem |
| | 1886 | /// Return the type of the dual problem |
| | 1887 | |
| | 1888 | /// This function returns the type of the dual problem. |
| | 1889 | /// \see ProblemType |
| 1879 | 1890 | ProblemType dualType() const { |
| 1880 | 1891 | return _getDualType(); |
| 1881 | 1892 | } |
| 1882 | 1893 | |
| | 1894 | /// Return the primal value of the objective function |
| | 1895 | |
| | 1896 | /// This function returns the primal value of the objective function. |
| | 1897 | /// \return |
| | 1898 | /// - \ref INF or -\ref INF means either infeasibility or unboundedness |
| | 1899 | /// of the primal problem, depending on whether we minimize or maximize. |
| | 1900 | /// - \ref NaN if no primal solution is found. |
| | 1901 | /// - The (finite) objective value if an optimal solution is found. |
| | 1902 | Value primalValue() const { return _getPrimalValue()+obj_const_comp;} |
| | 1903 | |
| | 1904 | /// Return the primal value of the objective function |
| | 1905 | |
| | 1906 | /// This function returns the primal value of the objective function. |
| | 1907 | /// It is an alias for \ref primalValue(). |
| | 1908 | Value primal() const { return _getPrimalValue()+obj_const_comp;} |
| | 1909 | |
| 1883 | 1910 | /// Return the primal value of the column |
| 1884 | 1911 | |
| 1885 | | /// Return the primal value of the column. |
| | 1912 | /// This function returns the primal value of the given column. |
| 1886 | 1913 | /// \pre The problem is solved. |
| 1887 | 1914 | Value primal(Col c) const { return _getPrimal(cols(id(c))); } |
| 1888 | 1915 | |
| 1889 | 1916 | /// Return the primal value of the expression |
| 1890 | 1917 | |
| 1891 | | /// Return the primal value of the expression, i.e. the dot |
| 1892 | | /// product of the primal solution and the expression. |
| | 1918 | /// This function returns the primal value of the given expression, |
| | 1919 | /// i.e. the dot product of the primal solution and the expression. |
| 1893 | 1920 | /// \pre The problem is solved. |
| 1894 | 1921 | Value primal(const Expr& e) const { |
| 1895 | 1922 | double res = *e; |
| … |
… |
|
| 1898 | 1925 | } |
| 1899 | 1926 | return res; |
| 1900 | 1927 | } |
| 1901 | | /// Returns a component of the primal ray |
| | 1928 | |
| | 1929 | /// Return a component of the primal ray |
| 1902 | 1930 | |
| 1903 | 1931 | /// The primal ray is solution of the modified primal problem, |
| 1904 | 1932 | /// where we change each finite bound to 0, and we looking for a |
| … |
… |
|
| 1915 | 1943 | |
| 1916 | 1944 | /// Return the dual value of the row |
| 1917 | 1945 | |
| 1918 | | /// Return the dual value of the row. |
| | 1946 | /// This function returns the dual value of the given row. |
| 1919 | 1947 | /// \pre The problem is solved. |
| 1920 | 1948 | Value dual(Row r) const { return _getDual(rows(id(r))); } |
| 1921 | 1949 | |
| 1922 | 1950 | /// Return the dual value of the dual expression |
| 1923 | 1951 | |
| 1924 | | /// Return the dual value of the dual expression, i.e. the dot |
| 1925 | | /// product of the dual solution and the dual expression. |
| | 1952 | /// This function returns the dual value of the given dual expression, |
| | 1953 | /// i.e. the dot product of the dual solution and the dual expression. |
| 1926 | 1954 | /// \pre The problem is solved. |
| 1927 | 1955 | Value dual(const DualExpr& e) const { |
| 1928 | 1956 | double res = 0.0; |
| … |
… |
|
| 1932 | 1960 | return res; |
| 1933 | 1961 | } |
| 1934 | 1962 | |
| 1935 | | /// Returns a component of the dual ray |
| | 1963 | /// Return a component of the dual ray |
| 1936 | 1964 | |
| 1937 | 1965 | /// The dual ray is solution of the modified primal problem, where |
| 1938 | 1966 | /// we change each finite bound to 0 (i.e. the objective function |
| … |
… |
|
| 1949 | 1977 | |
| 1950 | 1978 | /// Return the basis status of the column |
| 1951 | 1979 | |
| | 1980 | /// This function returns the basis status of the column. |
| 1952 | 1981 | /// \see VarStatus |
| 1953 | 1982 | VarStatus colStatus(Col c) const { return _getColStatus(cols(id(c))); } |
| 1954 | 1983 | |
| 1955 | 1984 | /// Return the basis status of the row |
| 1956 | 1985 | |
| | 1986 | /// This function returns the basis status of the row. |
| 1957 | 1987 | /// \see VarStatus |
| 1958 | 1988 | VarStatus rowStatus(Row r) const { return _getRowStatus(rows(id(r))); } |
| 1959 | | |
| 1960 | | ///The value of the objective function |
| 1961 | | |
| 1962 | | ///\return |
| 1963 | | ///- \ref INF or -\ref INF means either infeasibility or unboundedness |
| 1964 | | /// of the primal problem, depending on whether we minimize or maximize. |
| 1965 | | ///- \ref NaN if no primal solution is found. |
| 1966 | | ///- The (finite) objective value if an optimal solution is found. |
| 1967 | | Value primal() const { return _getPrimalValue()+obj_const_comp;} |
| 1968 | 1989 | ///@} |
| 1969 | 1990 | |
| 1970 | | protected: |
| 1971 | | |
| 1972 | 1991 | }; |
| 1973 | 1992 | |
| 1974 | 1993 | |
| … |
… |
|
| 1976 | 1995 | /// |
| 1977 | 1996 | /// \brief Common base class for MIP solvers |
| 1978 | 1997 | /// |
| 1979 | | /// This class is an abstract base class for MIP solvers. This class |
| | 1998 | /// This class is an abstract base class for MIP solvers. It |
| 1980 | 1999 | /// provides a full interface for set and modify an MIP problem, |
| 1981 | 2000 | /// solve it and retrieve the solution. You can use one of the |
| 1982 | 2001 | /// descendants as a concrete implementation, or the \c Lp |
| … |
… |
|
| 1986 | 2005 | class MipSolver : virtual public LpBase { |
| 1987 | 2006 | public: |
| 1988 | 2007 | |
| 1989 | | /// The problem types for MIP problems |
| | 2008 | /// \brief The problem types for MIP problems |
| | 2009 | /// |
| | 2010 | /// The problem types for MIP problems. |
| 1990 | 2011 | enum ProblemType { |
| 1991 | 2012 | /// = 0. Feasible solution hasn't been found (but may exist). |
| 1992 | 2013 | UNDEFINED = 0, |
| … |
… |
|
| 2010 | 2031 | |
| 2011 | 2032 | ///@{ |
| 2012 | 2033 | |
| 2013 | | /// Solve the MIP problem at hand |
| | 2034 | ///\brief Solve the specified MIP problem |
| 2014 | 2035 | /// |
| | 2036 | ///This function solves the specified MIP problem. |
| 2015 | 2037 | ///\return The result of the optimization procedure. Possible |
| 2016 | 2038 | ///values and their meanings can be found in the documentation of |
| 2017 | 2039 | ///\ref SolveExitStatus. |
| … |
… |
|
| 2022 | 2044 | ///\name Set Column Type |
| 2023 | 2045 | ///@{ |
| 2024 | 2046 | |
| 2025 | | ///Possible variable (column) types (e.g. real, integer, binary etc.) |
| 2026 | | enum ColTypes { |
| | 2047 | /// The column types for MIP problems. |
| | 2048 | |
| | 2049 | /// The column (variable) types for MIP problems. |
| | 2050 | /// |
| | 2051 | enum ColType { |
| 2027 | 2052 | /// = 0. Continuous variable (default). |
| 2028 | 2053 | REAL = 0, |
| 2029 | 2054 | /// = 1. Integer variable. |
| 2030 | 2055 | INTEGER = 1 |
| 2031 | 2056 | }; |
| 2032 | 2057 | |
| | 2058 | /// \brief The column types for MIP problems. It is an obsolete alias for |
| | 2059 | /// \ref ColType. |
| | 2060 | typedef ColType ColTypes; |
| | 2061 | |
| 2033 | 2062 | ///Sets the type of the given column to the given type |
| 2034 | 2063 | |
| 2035 | | ///Sets the type of the given column to the given type. |
| | 2064 | ///This function sets the type of the given column to the given type. |
| 2036 | 2065 | /// |
| 2037 | 2066 | void colType(Col c, ColTypes col_type) { |
| 2038 | 2067 | _setColType(cols(id(c)),col_type); |
| … |
… |
|
| 2040 | 2069 | |
| 2041 | 2070 | ///Gives back the type of the column. |
| 2042 | 2071 | |
| 2043 | | ///Gives back the type of the column. |
| | 2072 | ///This function gives back the type of the column. |
| 2044 | 2073 | /// |
| 2045 | 2074 | ColTypes colType(Col c) const { |
| 2046 | 2075 | return _getColType(cols(id(c))); |
| … |
… |
|
| 2051 | 2080 | |
| 2052 | 2081 | ///@{ |
| 2053 | 2082 | |
| 2054 | | /// The type of the MIP problem |
| | 2083 | /// Return the type of the MIP problem |
| | 2084 | |
| | 2085 | /// This function returns the type of the MIP problem. |
| | 2086 | /// \see ProblemType |
| 2055 | 2087 | ProblemType type() const { |
| 2056 | 2088 | return _getType(); |
| 2057 | 2089 | } |
| 2058 | 2090 | |
| 2059 | | /// Return the value of the row in the solution |
| | 2091 | /// Return the value of the objective function |
| | 2092 | |
| | 2093 | /// This function returns the value of the objective function. |
| | 2094 | /// \return |
| | 2095 | /// - \ref INF or -\ref INF means either infeasibility or unboundedness |
| | 2096 | /// of the problem, depending on whether we minimize or maximize. |
| | 2097 | /// - \ref NaN if no primal solution is found. |
| | 2098 | /// - The (finite) objective value if an optimal solution is found. |
| | 2099 | Value solValue() const { return _getSolValue()+obj_const_comp;} |
| 2060 | 2100 | |
| 2061 | | /// Return the value of the row in the solution. |
| | 2101 | /// Return the value of the objective function |
| | 2102 | |
| | 2103 | /// This function returns value of the objective function. |
| | 2104 | /// It is an alias for \ref solValue(). |
| | 2105 | Value sol() const { return _getSolValue()+obj_const_comp;} |
| | 2106 | |
| | 2107 | /// Return the value of the column |
| | 2108 | |
| | 2109 | /// This function returns the value of the given column in the solution. |
| 2062 | 2110 | /// \pre The problem is solved. |
| 2063 | 2111 | Value sol(Col c) const { return _getSol(cols(id(c))); } |
| 2064 | 2112 | |
| 2065 | | /// Return the value of the expression in the solution |
| | 2113 | /// Return the value of the expression |
| 2066 | 2114 | |
| 2067 | | /// Return the value of the expression in the solution, i.e. the |
| 2068 | | /// dot product of the solution and the expression. |
| | 2115 | /// This function returns the value of the given expression in the solution, |
| | 2116 | /// i.e. the dot product of the solution and the expression. |
| 2069 | 2117 | /// \pre The problem is solved. |
| 2070 | 2118 | Value sol(const Expr& e) const { |
| 2071 | 2119 | double res = *e; |
| … |
… |
|
| 2074 | 2122 | } |
| 2075 | 2123 | return res; |
| 2076 | 2124 | } |
| 2077 | | ///The value of the objective function |
| 2078 | | |
| 2079 | | ///\return |
| 2080 | | ///- \ref INF or -\ref INF means either infeasibility or unboundedness |
| 2081 | | /// of the problem, depending on whether we minimize or maximize. |
| 2082 | | ///- \ref NaN if no primal solution is found. |
| 2083 | | ///- The (finite) objective value if an optimal solution is found. |
| 2084 | | Value solValue() const { return _getSolValue()+obj_const_comp;} |
| | 2125 | |
| 2085 | 2126 | ///@} |
| 2086 | 2127 | |
| 2087 | 2128 | protected: |