{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## My First Robust Problem" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We consider a simple linear optimization problem with an ellipsoidal uncertainty set. (TODO complete)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import cvxpy as cp\n", "import numpy as np\n", "import lropt as lr" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "n = 2\n", "P = np.array([[1.,2],[1.,0.]])\n", "A = np.eye(2)\n", "b = np.zeros(2)\n", "c = np.array([2,1])\n", "a = np.array([.4,0.5])\n", "\n", "u = lr.UncertainParameter(n,\n", " uncertainty_set=lr.Ellipsoidal(A=A, b=b))\n", "\n", "x = cp.Variable(n)\n", "\n", "objective = cp.Minimize(c @ x)\n", "constraints = [(P @ u + a) @ x <= 10]\n", "\n", "prob = lr.RobustProblem(objective, constraints)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "optimal value = -20.76298271930384\n", "optimal solution = [ -1.83921308 -17.08455655]\n" ] } ], "source": [ "prob.solve()\n", "\n", "print(\"optimal value = \", objective.value)\n", "print(\"optimal solution = \", x.value)\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "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.11.3" }, "vscode": { "interpreter": { "hash": "e3ed6dde042e78d86e091991aef4e6276872e8fbcb7e1edcb6e9eacd7157f213" } } }, "nbformat": 4, "nbformat_minor": 4 }