{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **Using the low-level API function _loadproblem()_**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***loadlp.ipynb***\n", "\n", "This example shows how to load a problem using the [loadproblem()](https://www.fico.com/fico-xpress-optimization/docs/latest/solver/optimizer/python/HTML/problem.loadproblem.html) functionality and solve it via the FICO® Xpress Python interface.\n", "\n", "© Copyright 2025 Fair Isaac Corporation\n", "\n", "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n", " \n", "Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n", "\n", "This example uses FICO® Xpress software. By running it, you agree to the Community License terms of the [Xpress Shrinkwrap License Agreement](https://community.fico.com/s/contentdocument/06980000002h0i5AAA) with respect to the FICO® Xpress software. See the [licensing options](https://www.fico.com/en/fico-xpress-trial-and-licensing-options) overview for additional details and information about obtaining a paid license." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Install the xpress package\n", "%pip install -q xpress" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Start by importing the xpress Python package and create an Xpress problem." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import xpress as xp\n", "\n", "p = xp.problem()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Construct the following optimization problem with one call to [loadproblem()](https://www.fico.com/fico-xpress-optimization/docs/latest/solver/optimizer/python/HTML/problem.loadproblem.html) containing three variables with different bounds, and four constraints:\n", "\n", "$$\n", "\\min 3x_{1} + 4x_{2} + 5x_{3} \n", "$$\n", "\n", "subject to:\n", "\n", "$$\n", "x_{1} + x_{2} \\geq -2.4 \\\\\n", "x_{1} + x_{3} \\geq -3 \\\\\n", "x_{2} + x_{3} = 4 \\\\\n", "x_{1} + x_{2} + x_{3} \\leq 5 \\\\\n", "$$\n", "\n", "with the following bounds:\n", "\n", "$$\n", "-1 \\leq x_{1} \\leq 3 \\\\\n", "-1 \\leq x_{2} \\leq 5 \\\\\n", "-1 \\leq x_{3} \\leq 8\\\\\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As a first step in the transformation of the mathematical problem into the form required by the function we write the problem in the form of a table where the columns represent the decision variables and the rows are the constraints. All non-zero coefficients are then entered into this table, resulting in the problem matrix, completed by the operators and the constant terms (the latter are usually refered to as the right hand side, RHS, values).\n", "\n", "
x1 | x2 | x3 | rowtype | rhs | ||
---|---|---|---|---|---|---|
Constraint | 0 | 1 | 1 | 'G' | -2.4 | |
1 | 1 | 1 | 'G' | -3 | ||
2 | 1 | 1 | 'E' | 4 | 3 | 1 | 1 | 1 | 'L' | 5 | \n", "\n", "
start | 0 | 3 | 6 | 9 | ||