### Install highspy Python Package Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/index.md Instructions to install the highspy package using pip, the Python package installer. This command ensures the necessary library is available in your Python environment. ```shell $ pip install highspy ``` -------------------------------- ### Build HiGHS C# Example from Source with CMake Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/csharp.md Instructions to build the HiGHS C# example using CMake, enabling C# support and generating a binary in the build directory. This requires a C# compiler to be available. ```bash cmake -S. -Bbuild -DCSHARP=ON ``` -------------------------------- ### Build HiGHS from Source Code Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/cpp/index.md This sequence of commands navigates into the HiGHS directory, configures the build system using CMake, and then compiles the project in parallel. CMake version 3.15 or higher is required. ```bash cd HiGHS cmake -S. -B build cmake --build build --parallel ``` -------------------------------- ### HiGHS LP Hot Start Methods Source: https://github.com/ergo-code/highs/blob/master/docs/src/guide/further.md Methods to provide HiGHS with a user-defined solution or basis for warm-starting the LP solver. The basis passed to HiGHS need not be complete, as HiGHS can adjust it to the correct dimension. ```APIDOC // LP Solution/Basis Input void setSolution(Solution solution) // Provides a user-defined solution to HiGHS. void setBasis(Basis basis) // Provides a user-defined basis to HiGHS. ``` -------------------------------- ### Clone HiGHS Repository Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/cpp/index.md Clones the HiGHS project repository from GitHub to your local machine, allowing you to access the source code. ```bash git clone https://github.com/ERGO-Code/HiGHS.git ``` -------------------------------- ### Solve Optimization Model from MPS File Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/index.md A complete Python example demonstrating how to read an optimization model from an MPS file, solve it using the HiGHS solver, and then print its final status. This snippet illustrates a typical workflow for solving a problem. ```python import highspy h = highspy.Highs() filename = 'model.mps' h.readModel(filename) h.run() print('Model ', filename, ' has status ', h.getModelStatus()) ``` -------------------------------- ### Configure C Examples Build in CMake Source: https://github.com/ergo-code/highs/blob/master/examples/CMakeLists.txt This CMake snippet configures the build process for C examples. It checks if the BUILD_CXX_EXAMPLE flag is enabled (note: this flag name might be a typo in the original source if it's meant for C examples). If enabled, it finds all C source files ending with '_minimal.c', prints their names to the console, and then calls the custom 'highs_c_test' function for each found file. ```CMake if(BUILD_CXX_EXAMPLE) file(GLOB C_SRCS "*_minimal.c") # set(C_SRCS "call_highs_from_c_minimal.c") foreach(FILE_NAME IN LISTS C_SRCS) message(${FILE_NAME}) highs_c_test(${FILE_NAME}) endforeach() endif() ``` -------------------------------- ### Configure HiGHS solver options via file Source: https://github.com/ergo-code/highs/blob/master/docs/src/executable.md Illustrates how to specify HiGHS options using a dedicated options file. Options are defined as `name = value` pairs, one per line, with lines starting with `#` treated as comments. This example configures the solver to use PDLP and sets a specific KKT tolerance. ```shell solver = pdlp kkt_tolerance = 1e-4 ``` -------------------------------- ### HiGHS MIP Hot Start Methods Source: https://github.com/ergo-code/highs/blob/master/docs/src/guide/further.md Method to provide HiGHS with a partial or complete feasible assignment of integer variables for warm-starting the MIP solver. If a feasible solution is obtained, it will be used to provide an initial primal bound. ```APIDOC // MIP Solution Input void setSolution(MIPSolution solution) // Provides a (partial) feasible assignment of integer variables to HiGHS. ``` -------------------------------- ### Integrate HiGHS into CMake Project using find_package Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md Example CMakeLists.txt snippet demonstrating how to integrate an already installed HiGHS library into another C++ project using CMake's `find_package()` command. ```cmake project(LOAD_HIGHS LANGUAGES CXX) set(HIGHS_DIR path_to_highs_install/lib/cmake/highs) find_package(HIGHS REQUIRED) add_executable(main main.cpp) target_link_libraries(main highs::highs) ``` -------------------------------- ### Configure C++ Examples Build in CMake Source: https://github.com/ergo-code/highs/blob/master/examples/CMakeLists.txt This CMake snippet configures the build process for C++ examples. It first checks if the global BUILD_EXAMPLES flag is enabled, then specifically if BUILD_CXX_EXAMPLE is set. If both conditions are met, it finds all .cpp source files in the current directory and iterates through them, calling the custom 'highs_cxx_test' function for each found file. ```CMake if(NOT BUILD_EXAMPLES) return() endif() if(BUILD_CXX_EXAMPLE) file(GLOB CXX_SRCS "*.cpp") foreach(FILE_NAME IN LISTS CXX_SRCS) highs_cxx_test(${FILE_NAME}) endforeach() endif() ``` -------------------------------- ### Integrate HiGHS into CMake Project using FetchContent Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md Example CMakeLists.txt snippet showing how to include the HiGHS source code directly into a project using CMake's `FetchContent` module, allowing for in-project compilation. ```cmake project(LOAD_HIGHS LANGUAGES CXX) include(FetchContent) FetchContent_Declare( highs GIT_REPOSITORY "https://github.com/ERGO-Code/HiGHS.git" GIT_TAG "latest" ) FetchContent_MakeAvailable(highs) add_executable(main call_from_cpp.cc) target_link_libraries(main highs::highs) ``` -------------------------------- ### Build HiGHS Documentation Locally with Julia Source: https://github.com/ergo-code/highs/blob/master/docs/README.md This command initiates the local build process for the HiGHS project documentation. It requires Julia to be installed on the system. The first execution will automatically download and install necessary Julia packages, which may take a few minutes. The generated website will be located in the 'build/' directory. ```Bash $ julia make.jl ``` -------------------------------- ### Install NVIDIA CUDA Toolkit and Utilities via APT Source: https://github.com/ergo-code/highs/blob/master/highs/pdlp/README.md Commands to install the NVIDIA CUDA Toolkit and specific utility versions using the APT package manager on Linux. This method might lead to version conflicts if drivers are missing or if different CUDA versions are present, suggesting direct installation from the NVIDIA website as an alternative. ```bash apt install nvidia-cuda-toolkit apt install nvidia-utils-515 ``` -------------------------------- ### Install highspy Python Package from Source Source: https://github.com/ergo-code/highs/blob/master/README.md Instructions to build and install the `highspy` Python wrapper directly from the HiGHS source code directory. This method is used when installing from a local clone of the HiGHS repository. ```shell pip install . ``` -------------------------------- ### Install HiGHS to Custom Directory Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md Commands to build and install HiGHS to a user-specified directory by setting the `CMAKE_INSTALL_PREFIX` flag during CMake configuration. ```bash cmake -S. -B build -DCMAKE_INSTALL_PREFIX=/path/to/highs_install cmake --build build --parallel cmake --install build ``` -------------------------------- ### Install highs-bin Executable Source: https://github.com/ergo-code/highs/blob/master/app/CMakeLists.txt This snippet defines the installation rule for the `highs-bin` executable. It specifies that the executable should be installed as a runtime component to the `CMAKE_INSTALL_BINDIR` and exported as part of the `highs-targets` package. ```CMake # install the binary install(TARGETS highs-bin EXPORT highs-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### General Usage of CMake Options Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md Illustrates the general pattern for setting CMake options using `-D=` during the configuration step, followed by the build command. ```shell cmake -S. -Bbuild cmake --build build ``` -------------------------------- ### Initialize HiGHS Solver Object Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/index.md Code to create an instance of the HiGHS solver object. This initialization is a prerequisite before making any calls to the HiGHS Python library's methods. ```python h = highspy.Highs() ``` -------------------------------- ### Efficiently Extract Solution Values from HiGHS Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/index.md Illustrates how to efficiently extract column values from a HiGHS solution object. It demonstrates converting the solution array to a Python list to avoid slow entry-by-entry access, significantly improving performance for large solutions. ```python import highspy h = highspy.Highs() h.readModel('model.mps') h.run() solution = h.getSolution() num_vars = len(solution.col_value) value = [solution.col_value[icol] for icol in range(num_vars)] col_value = list(solution.col_value) value = [col_value[icol] for icol in range(num_vars)] ``` -------------------------------- ### Run HiGHS using Nix Flake (GitHub) Source: https://github.com/ergo-code/highs/blob/master/README.md This command allows running the HiGHS binary directly from its GitHub Nix flake, enabling execution without local cloning or installation, requiring only Nix to be installed. ```shell nix run github:ERGO-Code/HiGHS ``` -------------------------------- ### Install HiGHS.jl Package Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/julia/index.md This snippet demonstrates how to install the HiGHS.jl package using Julia's Pkg manager. This command also handles the download and installation of the necessary HiGHS binaries. ```julia import Pkg Pkg.add("HiGHS") ``` -------------------------------- ### Test HiGHS Build (Windows) Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md Command to run quick tests on Windows, requiring the configuration type (e.g., Release) to be specified. ```bash ctest -C Release ``` -------------------------------- ### Import highspy Library in Python Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/index.md Demonstrates how to import the highspy library into a Python program. This step is essential to access HiGHS functionalities within your script. ```python import highspy ``` -------------------------------- ### Install HiGHS to Default Location Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md Command to install the built HiGHS library and executable to the default system-wide location. This operation may require administrative permissions. ```bash cmake --install build ``` -------------------------------- ### Install HiGHS .NET NuGet Package Source: https://github.com/ergo-code/highs/blob/master/nuget/README.md This command adds the HiGHS.Native NuGet package to a C# project using the dotnet CLI. It specifies version 1.11.0 for the package. ```Shell dotnet add package Highs.Native --version 1.11.0 ``` -------------------------------- ### Mathematical Formulation of an Optimization Model Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Presents the mathematical formulation of a simple linear optimization problem, including the objective function, constraints, and variable bounds. This serves as the basis for the subsequent code examples demonstrating model building in HiGHS. ```raw minimize f = x0 + x1 subject to x1 <= 7 5 <= x0 + 2x1 <= 15 6 <= 3x0 + 2x1 0 <= x0 <= 4; 1 <= x1 ``` -------------------------------- ### Initialize HiGHS Python Library Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Initializes the HiGHS solver instance and imports necessary libraries like highspy and numpy. This step is prerequisite for all subsequent operations with the HiGHS Python library. ```python import highspy import numpy as np h = highspy.Highs() ``` -------------------------------- ### Run HiGHS using Nix Flake (Local) Source: https://github.com/ergo-code/highs/blob/master/README.md This command executes the HiGHS binary directly from the local Nix flake, providing a convenient way to run the solver without explicit installation, assuming Nix is set up. ```shell nix run . ``` -------------------------------- ### Verify CUDA Compiler Installation Source: https://github.com/ergo-code/highs/blob/master/highs/pdlp/README.md Checks if the NVIDIA CUDA compiler (`nvcc`) is correctly installed and accessible in the system's PATH by displaying its version information. A successful output indicates that the CUDA development environment is ready. ```bash nvcc --version ``` -------------------------------- ### Configure Fortran API Build and Installation in CMake Source: https://github.com/ergo-code/highs/blob/master/highs/CMakeLists.txt This CMake block handles the compilation and installation of the Fortran API for HiGHS. It defines the Fortran source files, sets the module directory, creates a library, links it against the main HiGHS library, and installs the compiled library and Fortran module files to their respective installation paths. ```CMake set(fortransources interfaces/highs_fortran_api.f90) set(CMAKE_Fortran_MODULE_DIRECTORY ${HIGHS_BINARY_DIR}/modules) add_library(FortranHighs interfaces/highs_fortran_api.f90) if(NOT FAST_BUILD) target_link_libraries(FortranHighs PUBLIC libhighs) else() target_link_libraries(FortranHighs PUBLIC highs) endif() install(TARGETS FortranHighs LIBRARY ARCHIVE RUNTIME INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs MODULES DESTINATION modules) if(NOT MSVC) install(FILES ${HIGHS_BINARY_DIR}/modules/highs_fortran_api.mod DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs/fortran) else() install(FILES ${HIGHS_BINARY_DIR}/modules/${CMAKE_BUILD_TYPE}/highs_fortran_api.mod DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs/fortran) endif() ``` -------------------------------- ### Pass Optimization Model from HighsLp Instance Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Demonstrates how to pass an entire optimization model to HiGHS from a pre-defined `HighsLp` instance. This involves populating the `HighsLp` object with column costs, bounds, row bounds, and the sparse constraint matrix data, then passing it to the solver. ```python inf = highspy.kHighsInf # Define a HighsLp instance lp = highspy.HighsLp() lp.num_col_ = 2; lp.num_row_ = 3; lp.col_cost_ = np.array([1, 1], dtype=np.double) lp.col_lower_ = np.array([0, 1], dtype=np.double) lp.col_upper_ = np.array([4, inf], dtype=np.double) lp.row_lower_ = np.array([-inf, 5, 6], dtype=np.double) lp.row_upper_ = np.array([7, 15, inf], dtype=np.double) # In a HighsLp instance, the number of nonzeros is given by a fictitious final start lp.a_matrix_.start_ = np.array([0, 2, 5]) lp.a_matrix_.index_ = np.array([1, 2, 0, 1, 2]) lp.a_matrix_.value_ = np.array([1, 3, 1, 2, 2], dtype=np.double) h.passModel(lp) ``` -------------------------------- ### Set Highs Solution Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Function to provide an initial or known solution to the Highs solver, which can be used to warm-start the optimization process. ```APIDOC Set solution: setSolution() ``` -------------------------------- ### Configure mip_max_start_nodes Source: https://github.com/ergo-code/highs/blob/master/docs/src/options/definitions.md Sets the maximum number of nodes the MIP solver can explore when completing a partial MIP start. ```APIDOC mip_max_start_nodes: description: MIP solver max number of nodes when completing a partial MIP start type: integer range: {0, 2147483647} default: 500 ``` -------------------------------- ### Build Optimization Model using General HiGHS Interface (addCols/addRows) Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Demonstrates an alternative general interface for model building using `addCols` and `addRows`. This method allows adding multiple columns and rows simultaneously by providing arrays for costs, bounds, and sparse matrix data, suitable for larger-scale model construction. ```python inf = highspy.kHighsInf # The constraint matrix is defined with the rows below, but parameters # for an empty (column-wise) matrix must be passed cost = np.array([1, 1], dtype=np.double) lower = np.array([0, 1], dtype=np.double) upper = np.array([4, inf], dtype=np.double) num_nz = 0 start = 0 index = 0 value = 0 h.addCols(2, cost, lower, upper, num_nz, start, index, value) # Add the rows, with the constraint matrix row-wise lower = np.array([-inf, 5, 6], dtype=np.double) upper = np.array([7, 15, inf], dtype=np.double) num_nz = 5 start = np.array([0, 1, 3]) index = np.array([1, 0, 1, 0, 1]) value = np.array([1, 2, 1, 3, 2], dtype=np.double) h.addRows(3, lower, upper, num_nz, start, index, value) ``` -------------------------------- ### Solving a HighsModel with HiGHS in C++ Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/cpp/library.md Provides a C++ example demonstrating the steps to initialize a HiGHS solver instance, pass a previously defined HighsModel, execute the solver, and verify the return status and model status. ```C++ // Create a Highs instance Highs highs; HighsStatus return_status; // Pass the model to HiGHS return_status = highs.passModel(model); assert(return_status==HighsStatus::kOk); // Get a const reference to the LP data in HiGHS const HighsLp& lp = highs.getLp(); // Solve the model return_status = highs.run(); assert(return_status==HighsStatus::kOk); // Get the model status const HighsModelStatus& model_status = highs.getModelStatus(); assert(model_status==HighsModelStatus::kOptimal); ``` -------------------------------- ### Manage Highs Option Values Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Functions for setting and retrieving configuration options within the Highs solver, allowing users to customize its behavior. ```APIDOC Option values: setOptionValue() getOptionValue() ``` -------------------------------- ### HiGHS C# API Integration Guidelines (PInvoke) Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/csharp.md Key considerations and observations for calling the native HiGHS library from C# using PInvoke. This includes guidance on locating the native library at runtime, managing dependencies, and adapting to library naming conventions. ```APIDOC HiGHS C# API PInvoke Considerations: - PInvoke Declarations: - Location: `HiGHS/highs/interfaces/highs_csharp_api.cs` contains all necessary PInvoke declarations. - Native Library Discovery: - Requirement: The native HiGHS library (`highs.dll`, `libhighs.dll`, `libhighs.so`, etc., depending on platform) must be discoverable at runtime. - Methods: - Copying: Copy the native library next to your C# executable (often works). - MSBuild: Utilize MSBuild for deployment. - System-wide Installation: On Linux, installing HiGHS system-wide can work. - Dependencies: - Requirement: All dependencies of the HiGHS library must be found. - Example: If HiGHS was built with Visual C++, ensure `MSVCRuntime` is installed on the target machine. - Library Naming: - Constant: The constant "highslibname" might need to be changed depending on the name of your HiGHS library. - Reference: Consult Microsoft documentation on cross-platform P/Invoke for details. - Usage: - Call Methods: Invoke methods defined in `highs_csharp_api.cs` to interact with HiGHS. ``` -------------------------------- ### HiGHS CMake Build Options Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md A list of available CMake options that can be passed to modify how the HiGHS code is built, including their default values and relevant notes. ```APIDOC CMAKE_BUILD_TYPE: Release (see CMake documentation) BUILD_SHARED_LIBS: ON (*) (Build shared libraries (.so or .dyld). * OFF by default on Windows) BUILD_CXX: ON (Build C++) FORTRAN: OFF (Build Fortran interface) CSHARP: OFF (Build CSharp wrapper) BUILD_DOTNET: OFF (Build .Net package) PYTHON_BUILD_SETUP: OFF (Build Python bindings. Called at `pip install` from pyproject.toml) ZLIB: ON (Use ZLIB if available) ALL_TESTS: OFF (Run unit tests and extended instance test set) ``` -------------------------------- ### Configure and Install Highs CMake and Pkg-config Files (CMake) Source: https://github.com/ergo-code/highs/blob/master/highs/CMakeLists.txt This section handles the generation and installation of 'highs-config.cmake' and 'highs.pc' files. These files allow other projects to easily find and link against the Highs library using CMake's find_package or pkg-config. ```CMake # Configure the config file for the build tree: # Either list all the highs/* directories here, or put explicit paths in all the # include statements. # M reckons that the latter is more transparent, and I'm inclined to agree. set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/highs" "${HIGHS_BINARY_DIR}") configure_file(${PROJECT_SOURCE_DIR}/cmake/highs-config.cmake.in "${HIGHS_BINARY_DIR}/highs-config.cmake" @ONLY) # Configure the config file for the install set(CONF_INCLUDE_DIRS "\${CMAKE_CURRENT_LIST_DIR}/../../../${CMAKE_INSTALL_INCLUDEDIR}/highs") configure_file(${PROJECT_SOURCE_DIR}/cmake/highs-config.cmake.in "${HIGHS_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/highs-config.cmake" @ONLY) # Configure the pkg-config file for the install configure_file(${PROJECT_SOURCE_DIR}/highs.pc.in "${HIGHS_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/highs.pc" @ONLY) # Install the targets of the highs export group, the config file so that other # cmake-projects can link easily against highs, and the pkg-config flie so that # other projects can easily build against highs install(EXPORT highs-targets FILE highs-targets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/highs) install(FILES "${HIGHS_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/highs-config.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/highs) install(FILES "${HIGHS_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/highs.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) ``` -------------------------------- ### Build 32-bit HiGHS on Windows Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md Commands to build a 32-bit version of HiGHS on Windows, as the default build is 64-bit. This is achieved by specifying the architecture with `-A Win32`. ```shell cmake -A Win32 -S . -B buildWin32 cmake --build buildWin32 ``` -------------------------------- ### Test HiGHS Build (Linux/macOS) Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md Command to run a quick test after building HiGHS to verify successful compilation from within the build folder. ```bash ctest ``` -------------------------------- ### Highs Presolve and Postsolve Operations Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Functions related to the presolving and postsolving phases of the Highs optimization process, including status checks, model retrieval, and logging. ```APIDOC Presolve/postsolve: presolve() getPresolvedLp() getPresolvedModel() getPresolveLog() getPresolveOrigColsIndex() getPresolveOrigRowsIndex() getModelPresolveStatus() writePresolvedModel() presolveStatusToString() presolveRuleTypeToString() postsolve() ``` -------------------------------- ### Read Optimization Model from File Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Demonstrates how to read an optimization model into HiGHS from MPS or CPLEX LP files using the `readModel` method. It shows reading from two different filenames and printing the status returned by the operation. ```python # Read a model from MPS file model.mps filename = 'model.mps' status = h.readModel(filename) print('Reading model file ', filename, ' returns a status of ', status) filename = 'model.dat' status = h.readModel(filename) print('Reading model file ', filename, ' returns a status of ', status) ``` -------------------------------- ### Configure solution_file Source: https://github.com/ergo-code/highs/blob/master/docs/src/options/definitions.md Sets the path for writing a solution file. An empty string indicates no file is written. ```APIDOC solution_file: description: Write solution file type: string default: "" ``` -------------------------------- ### Build Optimization Model using Simplified HiGHS Interface Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Constructs the optimization model using HiGHS's simplified Python interface. It demonstrates adding variables with bounds using `addVariable`, adding constraints with `addConstr`, and setting the objective function directly using `minimize`. ```python x0 = h.addVariable(lb = 0, ub = 4) x1 = h.addVariable(lb = 1, ub = 7) h.addConstr(5 <= x0 + 2*x1 <= 15) h.addConstr(6 <= 3*x0 + 2*x1) h.minimize(x0 + x1) ``` -------------------------------- ### Solve the Optimization Model Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Executes the HiGHS solver on the currently loaded optimization model. This initiates the optimization process to find an optimal solution based on the defined objective and constraints. ```python h.run() ``` -------------------------------- ### Build HiGHS with Specific Visual Studio Version Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md Commands to build HiGHS using a specific version of Visual Studio on Windows by specifying the generator with the `-G` option. ```shell cmake -G "Visual Studio 17 2022" -S . -B build cmake --build build ``` -------------------------------- ### Building a HighsModel Instance in C++ Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/cpp/library.md Demonstrates how to programmatically construct a HighsModel object in C++. This example defines a linear programming problem by setting objective sense, offset, column costs, variable bounds, row bounds, and the sparse matrix structure in a column-wise format. ```C++ // Create and populate a HighsModel instance for the LP // Min f = x_0 + x_1 + 3 // s.t. x_1 <= 7 // 5 <= x_0 + 2x_1 <= 15 // 6 <= 3x_0 + 2x_1 // 0 <= x_0 <= 4; 1 <= x_1 // Although the first constraint could be expressed as an upper // bound on x_1, it serves to illustrate a non-trivial packed // column-wise matrix. HighsModel model; model.lp_.num_col_ = 2; model.lp_.num_row_ = 3; model.lp_.sense_ = ObjSense::kMinimize; model.lp_.offset_ = 3; model.lp_.col_cost_ = {1.0, 1.0}; model.lp_.col_lower_ = {0.0, 1.0}; model.lp_.col_upper_ = {4.0, 1.0e30}; model.lp_.row_lower_ = {-1.0e30, 5.0, 6.0}; model.lp_.row_upper_ = {7.0, 15.0, 1.0e30}; // Here the orientation of the matrix is column-wise model.lp_.a_matrix_.format_ = MatrixFormat::kColwise; // a_start_ has num_col_+1 entries, and the last entry is the number // of nonzeros in A, allowing the number of nonzeros in the last // column to be defined model.lp_.a_matrix_.start_ = {0, 2, 5}; model.lp_.a_matrix_.index_ = {1, 2, 0, 1, 2}; model.lp_.a_matrix_.value_ = {1.0, 3.0, 1.0, 2.0, 2.0}; ``` -------------------------------- ### HiGHS API for Reporting Solution Results Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md References the API method for writing the solution to a file. This function is useful for persistent storage or external analysis of the optimization results, allowing for easy export of the solver's output. ```APIDOC HiGHS API for Result Reporting: - writeSolution() ``` -------------------------------- ### Print HiGHS Solution and Status Information Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Retrieves and prints various details about the solved model, including the solution, basis, solver information, and model status. It demonstrates how to interpret the results and status codes provided by HiGHS after an optimization run. ```python solution = h.getSolution() basis = h.getBasis() info = h.getInfo() model_status = h.getModelStatus() print('Model status = ', h.modelStatusToString(model_status)) print() print('Optimal objective = ', info.objective_function_value) print('Iteration count = ', info.simplex_iteration_count) print('Primal solution status = ', h.solutionStatusToString(info.primal_solution_status)) print('Dual solution status = ', h.solutionStatusToString(info.dual_solution_status)) print('Basis validity = ', h.basisValidityToString(info.basis_validity)) ``` -------------------------------- ### HiGHS API for Extracting Solution Results Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Lists key API methods available in HiGHS for extracting various components of the optimization solution and solver information after a run. These include model status, objective values, solution details, and basis information. ```APIDOC HiGHS API for Result Extraction: - getModelStatus() - getInfo() - getSolution() - getBasis() - getObjectiveValue() - getDualObjectiveValue() ``` -------------------------------- ### Build HiGHS Release Version on Windows Source: https://github.com/ergo-code/highs/blob/master/cmake/README.md Commands to build the release version of HiGHS binaries on Windows, as CMake defaults to debug builds. The `--config Release` option ensures a release build. ```shell cmake -S . -B build cmake --build build --config Release ``` -------------------------------- ### Build HiGHS from Source using CMake Source: https://github.com/ergo-code/highs/blob/master/README.md This snippet demonstrates how to generate build files and compile the HiGHS project using CMake. It creates a 'build' subdirectory for the compiled artifacts, installing the executable and library. ```shell cmake -S . -B build cmake --build build ``` -------------------------------- ### Define and Configure highs Executable (Non-Fast Build) Source: https://github.com/ergo-code/highs/blob/master/app/CMakeLists.txt This section defines the `highs` executable when `FAST_BUILD` is not enabled. It specifies the source file, applies Unix-specific compile options, links against `libhighs`, includes necessary directories, and sets up the installation rule for the binary. ```CMake else() # create highs binary using library without pic add_executable(highs) target_sources(highs PRIVATE RunHighs.cpp) if(UNIX) target_compile_options(highs PUBLIC "-Wno-unused-variable") target_compile_options(highs PUBLIC "-Wno-unused-const-variable") endif() target_link_libraries(highs libhighs) target_include_directories(highs PRIVATE $ ) # install the binary install(TARGETS highs EXPORT highs-targets RUNTIME) endif() ``` -------------------------------- ### Initialize HiGHS and Run Optimization in Browser Source: https://github.com/ergo-code/highs/blob/master/app/highs_webdemo_shell.html This JavaScript code initializes the HiGHS solver in a web environment using a custom print function to display output in a textarea. It sets up an input textarea with a sample linear programming problem, clears an output area, and attaches an event listener to a 'run' button to execute the optimization problem using HiGHS's file system and main call functionality. ```JavaScript main = async () => { const printInTextarea = function(text) { if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' '); // These replacements are necessary if you render to raw HTML //text = text.replace(/&/g, "&"); //text = text.replace(//g, ">"); //text = text.replace('\n', '
', 'g'); // console.log(text); if (element) { element.value += text + "\n"; element.scrollTop = element.scrollHeight; // focus on bottom } } const highs = await HiGHS({ print: printInTextarea, printErr: printInTextarea }) const inputTextarea = document.getElementById('input'); inputTextarea.value = `Maximize obj: x1 + 2 x2 + 3 x3 + x4 Subject To c1: - x1 + x2 + x3 + 10 x4 <= 20 c2: x1 - 3 x2 + x3 <= 30 c3: x2 - 3.5 x4 = 0 Bounds 0 <= x1 <= 40 2 <= x4 <= 3 General x4 End`; const element = document.getElementById('output'); const clearOutput = (v) => { element.value = v || ''; } clearOutput('Click on "Optimize!"') // clear browser cache const runButton = document.getElementById('run'); runButton.addEventListener("click", () => { clearOutput() const inputFilename = 'inputFile.lp' highs.FS.writeFile(inputFilename, inputTextarea.value) highs.callMain([inputFilename]) }) } main() ``` -------------------------------- ### Import NumPy for highspy Integration Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/index.md Shows how to import the NumPy library, commonly used alongside highspy for numerical operations and handling array structures. It's imported with the alias 'np' for convenience. ```python import numpy as np ``` -------------------------------- ### Configure write_solution_style Source: https://github.com/ergo-code/highs/blob/master/docs/src/options/definitions.md Defines the output style for solution files, supporting both human-readable ('pretty') and machine-readable ('raw') formats, with specific options for HiGHS and Glpsol. ```APIDOC write_solution_style: description: Style of solution file (raw = computer-readable, pretty = human-readable): -1 => HiGHS old raw (deprecated); 0 => HiGHS raw; 1 => HiGHS pretty; 2 => Glpsol raw; 3 => Glpsol pretty; 4 => HiGHS sparse raw type: integer range: {-1, 4} default: 0 ``` -------------------------------- ### Configure Highs Build Options Source: https://github.com/ergo-code/highs/blob/master/CMakeLists.txt Defines various build options for the Highs project, including whether to build examples (C++, C#) and the .NET package. These options are dependent on other build flags, allowing for flexible project compilation. ```CMake option(BUILD_EXAMPLES "Build examples" ON) message(STATUS "Build examples: ${BUILD_EXAMPLES}") CMAKE_DEPENDENT_OPTION(BUILD_CXX_EXAMPLE "Build cxx example" ON "BUILD_EXAMPLES;BUILD_CXX" OFF) message(STATUS "Build C++ example: ${BUILD_CXX_EXAMPLE}") CMAKE_DEPENDENT_OPTION(BUILD_CSHARP_EXAMPLE "Build CSharp example" ON "BUILD_EXAMPLES;CSHARP" OFF) message(STATUS "Build CSharp example: ${BUILD_CSHARP_EXAMPLE}") CMAKE_DEPENDENT_OPTION(BUILD_DOTNET "Build dotnet package" OFF "BUILD_EXAMPLES;CSHARP" OFF) message(STATUS "Build dotnet package: ${BUILD_DOTNET}") ``` -------------------------------- ### Configure read_solution_file Source: https://github.com/ergo-code/highs/blob/master/docs/src/options/definitions.md Sets the path for reading a solution file. An empty string indicates no file is read. ```APIDOC read_solution_file: description: Read solution file type: string default: "" ``` -------------------------------- ### HiGHS Command Line Interface Options Source: https://github.com/ergo-code/highs/blob/master/README.md Detailed documentation of the HiGHS command-line executable's options, including parameters for specifying model files, options files, solution files, basis files, and various solver settings like presolve, solver choice, parallelism, crossover, time limits, and random seed. It also lists options for ranging and printing version/help. ```APIDOC usage: ./bin/highs [options] [file] options: --model_file file File of model to solve. --options_file file File containing HiGHS options. --read_solution_file file File of solution to read. --read_basis_file text File of initial basis to read. --write_model_file text File for writing out model. --solution_file text File for writing out solution. --write_basis_file text File for writing out final basis. --presolve text Set presolve option to: "choose" * default "on" "off" --solver text Set solver option to: "choose" * default "simplex" "ipm" --parallel text Set parallel option to: "choose" * default "on" "off" --run_crossover text Set run_crossover option to: "choose" "on" * default "off" --time_limit float Run time limit (seconds - double). --random_seed int Seed to initialize random number generation. --ranging text Compute cost, bound, RHS and basic solution ranging: "on" "off" * default -v, --version Print version. -h, --help Print help. ``` -------------------------------- ### Generate HiGHS Options File Template (Shell) Source: https://github.com/ergo-code/highs/blob/master/docs/src/options/intro.md This shell command instructs the HiGHS executable to print a sample options file to the console. This file serves as a comprehensive reference, documenting all available HiGHS options and their default values. ```shell $ bin/highs --options_file="" ``` -------------------------------- ### Install HiGHS Public Header Files (CMake) Source: https://github.com/ergo-code/highs/blob/master/highs/CMakeLists.txt This snippet iterates through the list of header files defined for the HiGHS project and installs them into the standard include directory. It preserves the directory structure of the headers relative to the project source, ensuring proper organization in the installation path. It also installs a generated configuration header. ```CMake foreach(file ${headers}) get_filename_component(dir ${file} DIRECTORY) if(NOT dir STREQUAL "") string(REPLACE ../extern/ "" dir ${dir}) endif() install(FILES ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs/${dir}) endforeach() install(FILES ${HIGHS_BINARY_DIR}/HConfig.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs) ``` -------------------------------- ### Pack HiGHS .NET NuGet Package Locally Source: https://github.com/ergo-code/highs/blob/master/nuget/README.md This command uses the dotnet CLI to pack the locally built HiGHS .NET wrapper into a NuGet package. It specifies a release configuration and allows for versioning. ```Shell dotnet pack -c Release /p:Version=$version ``` -------------------------------- ### Install Highs Library Header Files (CMake) Source: https://github.com/ergo-code/highs/blob/master/highs/CMakeLists.txt This section iterates through the defined header files for the Highs library and configures their installation to the specified include directory, maintaining their relative path structure. ```CMake # install the header files of highs foreach(file ${headers}) get_filename_component(dir ${file} DIRECTORY) if(NOT dir STREQUAL "") string(REPLACE ../extern/ "" dir ${dir}) endif() install(FILES ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs/${dir}) endforeach() install(FILES ${HIGHS_BINARY_DIR}/HConfig.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs) ``` -------------------------------- ### Verify CUDA Compiler Installation Source: https://github.com/ergo-code/highs/blob/master/docs/src/guide/gpu.md This command checks if the NVIDIA CUDA compiler (`nvcc`) is installed and accessible in the system's PATH, displaying its version information. This verification is a crucial prerequisite before attempting to build HiGHS with GPU support. ```Bash nvcc --version ``` -------------------------------- ### Required NuGet Package Structure for Native Libraries Source: https://github.com/ergo-code/highs/blob/master/nuget/HowToAlternative.md Illustrates the necessary directory structure for a NuGet package to correctly include native shared libraries for different runtimes (linux-x64, linux-arm64, win-x64) alongside the .NET Standard API DLL. ```bash package/ |-- lib/ | |-- netstandard2.0/ | |-- highs_csharp_api.dll |-- runtimes/ | |-- linux-x64/ | | |-- native/ | | ! [linux-x64 native libraries] | |-- linux-arm64/ | | |-- native/ | | ! [linux-arm64 native libraries] | |-- win-x64/ | | |-- native/ | | ! [win-x64 native libraries] ``` -------------------------------- ### Install and Export Highs Library Build Targets (CMake) Source: https://github.com/ergo-code/highs/blob/master/highs/CMakeLists.txt This snippet configures the installation of the 'libhighs' target (library, archive, runtime) and sets up its export for use by other CMake projects. It also defines the build-tree export set. ```CMake install(TARGETS libhighs EXPORT highs-targets LIBRARY ARCHIVE RUNTIME INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs) # Add library targets to the build-tree export set export(TARGETS libhighs FILE "${HIGHS_BINARY_DIR}/highs-targets.cmake") ``` -------------------------------- ### Configure mip_improving_solution_file Source: https://github.com/ergo-code/highs/blob/master/docs/src/options/definitions.md Specifies the file path for reporting improving MIP solutions. An empty string disables reporting. ```APIDOC mip_improving_solution_file: description: File for reporting improving MIP solutions: not reported for an empty string "" type: string default: "" ``` -------------------------------- ### Install highspy Python Package via pip Source: https://github.com/ergo-code/highs/blob/master/README.md Instructions to install the `highspy` Python wrapper for HiGHS using the pip package manager. This command fetches the package from PyPi, making it readily available for use in Python projects. ```shell pip install highspy ``` -------------------------------- ### Configure RPATH for Build and Install Paths in CMake Source: https://github.com/ergo-code/highs/blob/master/CMakeLists.txt This CMake snippet configures the RPATH (Run-time search path) settings for executables and libraries. It enables `CMAKE_MACOSX_RPATH` for macOS and conditionally sets `CMAKE_BUILD_WITH_INSTALL_RPATH` and `CMAKE_SKIP_BUILD_RPATH` based on whether `BUILD_DOTNET` is enabled, influencing how shared libraries are found at runtime during development and after installation. ```CMake set(CMAKE_MACOSX_RPATH ON) if (BUILD_DOTNET) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) else() # use, i.e. don't skip the full RPATH for the build tree set(CMAKE_SKIP_BUILD_RPATH FALSE) # when building, don't use the install RPATH already # (but later on when installing) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) endif() ``` -------------------------------- ### Configure C# API Build and Example in CMake Source: https://github.com/ergo-code/highs/blob/master/highs/CMakeLists.txt This CMake section configures the build process for the C# API wrapper of HiGHS. It adds a shared library for the C# interface, enables unsafe code compilation for performance, and sets up an executable example demonstrating how to call HiGHS functionalities from a C# application. ```CMake message(STATUS "CSharp supported") set(csharpsources interfaces/highs_csharp_api.cs) add_library(HighsCsharp SHARED interfaces/highs_csharp_api.cs) add_library(${PROJECT_NAMESPACE}::HighsCsharp ALIAS HighsCsharp) target_compile_options(HighsCsharp PUBLIC "/unsafe") add_executable(csharpexample ../examples/call_highs_from_csharp.cs) target_compile_options(csharpexample PUBLIC "/unsafe") target_link_libraries(csharpexample PUBLIC HighsCsharp) ``` -------------------------------- ### Build HiGHS using Meson Source: https://github.com/ergo-code/highs/blob/master/README.md This snippet shows how to build HiGHS using the Meson build system, including enabling tests. It creates a build directory named 'bbdir' for the compiled output. ```shell meson setup bbdir -Dwith_tests=True meson test -C bbdir ``` -------------------------------- ### Build Optimization Model using General HiGHS Interface (addVar/addRow) Source: https://github.com/ergo-code/highs/blob/master/docs/src/interfaces/python/example-py.md Illustrates building the model using a more general interface, adding variables one by one with `addVar` and defining objective coefficients with `changeColCost`. Constraints are added using `addRow`, specifying non-zero coefficients by index and value. It also shows how to access the LP object and its dimensions. ```python inf = highspy.kHighsInf # Define two variables, first using identifiers for the bound values, # and then using constants lower = 0 upper = 4 h.addVar(lower, upper) h.addVar(1, inf) # Define the objective coefficients (costs) of the two variables, # identifying the variable by index, and changing its cost from the # default value of zero cost = 1 h.changeColCost(0, cost) h.changeColCost(1, 1) # Define constraints for the model # # The first constraint (x1<=7) has only one nonzero coefficient, # identified by variable index 1 and value 1 num_nz = 1 index = 1 value = 1 h.addRow(-inf, 7, num_nz, index, value) # The second constraint (5 <= x0 + 2x1 <= 15) has two nonzero # coefficients, so arrays of indices and values are required num_nz = 2 index = np.array([0, 1]) value = np.array([1, 2]) h.addRow(5, 15, num_nz, index, value) # The final constraint (6 <= 3x0 + 2x1) has the same indices but # different values num_nz = 2 value = np.array([3, 2]) h.addRow(6, inf, num_nz, index, value) # Access LP lp = h.getLp() num_nz = h.getNumNz() print('LP has ', lp.num_col_, ' columns', lp.num_row_, ' rows and ', num_nz, ' nonzeros') ```