└── LP Notebook.ipynb /LP Notebook.ipynb: -------------------------------------------------------------------------------- 1 | {"cells": [{"metadata": {}, "cell_type": "markdown", "source": "# Import Model Artifacts"}, {"metadata": {}, "cell_type": "code", "source": "from docplex.mp.model import Model\n", "execution_count": 5, "outputs": []}, {"metadata": {}, "cell_type": "code", "source": "m = Model(name='unit allocation')", "execution_count": 23, "outputs": []}, {"metadata": {}, "cell_type": "markdown", "source": "# Variables"}, {"metadata": {}, "cell_type": "code", "source": "foldyphone = m.continuous_var(name='foldyphone')\ntinyphone = m.continuous_var(name='tinyphone')", "execution_count": 24, "outputs": []}, {"metadata": {}, "cell_type": "code", "source": "foldyphonetime = 1.5\ntinyphonetime = 2", "execution_count": 25, "outputs": []}, {"metadata": {}, "cell_type": "markdown", "source": "# Constraints"}, {"metadata": {}, "cell_type": "code", "source": "foldyphoneprod = m.add_constraint(foldyphone >= 500)\ntinyphoneprod = m.add_constraint(tinyphone >= 200)\ntotalprod = m.add_constraint(m.sum([tinyphone*tinyphonetime, foldyphone*foldyphonetime]) <= 2999.5)", "execution_count": 26, "outputs": []}, {"metadata": {}, "cell_type": "markdown", "source": "# Goals"}, {"metadata": {}, "cell_type": "code", "source": "m.maximize(foldyphone*900 + tinyphone*1100)\n", "execution_count": 27, "outputs": []}, {"metadata": {}, "cell_type": "markdown", "source": "# Solution"}, {"metadata": {}, "cell_type": "code", "source": "sol = m.solve()", "execution_count": 28, "outputs": [{"output_type": "display_data", "data": {"text/plain": "", "text/html": "
"}, "metadata": {}}, {"output_type": "display_data", "data": {"text/plain": "", "text/html": "
"}, "metadata": {}}, {"output_type": "display_data", "data": {"text/plain": "", "text/html": "
"}, "metadata": {}}, {"output_type": "display_data", "data": {"text/plain": "", "text/html": "
"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "code", "source": "sol.display()\n", "execution_count": 31, "outputs": [{"output_type": "stream", "text": "solution for: unit allocation\nobjective: 1779700.000\nfoldyphone = 1733.000\ntinyphone = 200.000\n", "name": "stdout"}]}, {"metadata": {}, "cell_type": "code", "source": "tinyphone.solution_value", "execution_count": 30, "outputs": [{"output_type": "execute_result", "execution_count": 30, "data": {"text/plain": "200.0"}, "metadata": {}}]}, {"metadata": {}, "cell_type": "code", "source": "foldyphone.solution_value", "execution_count": 29, "outputs": [{"output_type": "execute_result", "execution_count": 29, "data": {"text/plain": "1733.0"}, "metadata": {}}]}], "metadata": {"kernelspec": {"name": "python3", "display_name": "Python 3.6", "language": "python"}, "language_info": {"name": "python", "version": "3.6.9", "mimetype": "text/x-python", "codemirror_mode": {"name": "ipython", "version": 3}, "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "file_extension": ".py"}}, "nbformat": 4, "nbformat_minor": 1} --------------------------------------------------------------------------------