{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\\begin{align*}\n", "-x &\\le 0 \\\\\n", "-y &\\le 0 \\\\\n", "x + y &\\le 1 \\\\[1ex]\n", "a_i x + b_i y &\\le c_i\n", "\\end{align*}" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "a = [-1, 0, 1]\n", "b = [0, -1, 1]\n", "c = [0, 0, 1]\n", "tocke = [(1, 2), (3, -2), (4, 0)]" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "p = MixedIntegerLinearProgram(maximization=True)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.2000000000004" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p.set_objective(p['k'])\n", "for xi, yi in tocke:\n", " for ai, bi, ci in zip(a, b, c):\n", " p.add_constraint(ai * (p['k'] * xi + p['x']) + bi * (p['k'] * yi + p['y']) <= ci)\n", "p.solve()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0.2000000000004, -0.20000000000039997, 0.3999999999988)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "k, x, y = p.get_values(p['k']), p.get_values(p['x']), p.get_values(p['y'])\n", "k, x, y" ] } ], "metadata": { "kernelspec": { "display_name": "SageMath 9.2.rc2", "language": "sage", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 4 }