Advertisement
Guest User

Untitled

a guest
May 26th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. {"nbformat_minor": 0, "cells": [{"execution_count": 7, "cell_type": "code", "source": "%load_ext ampl", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The ampl extension is already loaded. To reload it, use:\n %reload_ext ampl\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 8, "cell_type": "code", "source": "%%ampl\nreset;\n\n#define indices\nparam I>0; #index for product, i=1,...,I\n#param N>0; #index for processing step, l=1,...,N\nparam T>0; #index for time period , t=1,...,T\n#param Ni {1..I}; #index for number of steps to process product i.\n#param t>0; #index for time period, t=1,...,T.\nparam K>0 integer; #index for resources, k=1,...,K\n\n#define parameters\nparam V{1..I}; #shortange cost of product i at step l.\nparam h{1..I}; #holding cost of product i at step l\nparam L{1..I}; #production time (production lag) of product i at tep l.\nparam a{1..I,1..K}; #Amount of resource k used to produce a unit amount of product i at step 1\nparam b{1..I}; #Yield of product i at step l.\nparam C{1..K}; #Amount of resource k.\nparam D{1..I,1..T}; #Demand rate of product i at step l during period t. (Di,N(i)(t) is determined by production planning.\nparam I0{1..I}; #Initial WlP inventory for product i at step l.\n\n# define variables\nvar x{1..I,1..T} >= 0 integer ; #Output rate of product i realized at step l during period t. (bi,lxi,t(t) is usable output rate,net of yield loss.)\nvar B{1..I,1..T} >= 0 integer; #Shortage of product i at step 1 at the end of period t.\nvar II{1..I,0..T} >= 0 integer; #Inventory of product i of step l at the end of period t, i.e., inventory to be applied to step l + l w h e r e t = l . . . . . T.\n\n\n#objective \n#minimize WIP holding costs of intermediate steps plus shortage costs of the final step\nminimize WIP:\n sum {i in 1..I, t in 1..T} (V[i]*B[i,t] + h[i]*II[i,t]);\n \n# constraints 2\nsubject to Inv_balance { i in 1..I,t in 1..T}:\n ( II[i,t] = II[i,t-1] - x[i,t+L[i]]+ b[i]*x[i,t]);\n\n# constraints 3\nsubject to Inv_initial {i in 1..I, t in 1..T}:\n II[i,0] = I0[i]-x[i,1]*L[i];\n \n \n# constraints 4 \nsubject to Invbf {i in 1..I , t in 1..T}: \n b[i]*sum{z in 1..t} (x[i,z]) + B[i,t] - II[i,t] = sum{z in 1..t} (D[i,z]);\n\n# constraints 5 \nsubject to resource_req {k in 1..K, t in 1..T}:\n sum { i in 1..I} a[i,k]*x[i,t] <= C[k];\n \ndata;\n\nparam I := 2;\nparam T := 6;\nparam K := 2;\n\nparam V := 1 20 2 20;\nparam h := 1 10 2 10;\nparam L := 1 0 2 0;\n\nparam a : 1 2 :=\n 1 1 1 \n 2 1 1;\n\nparam b := 1 1 2 1;\n\nparam C := 1 10 2 20;\n\nparam D : 1 2 3 4 5 6:=\n 1 10 3 50 90 40 50 \n 2 2 20 2 200 100 20;\n \nparam I0 := 1 0 2 1; \n", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "\n", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 9, "cell_type": "code", "source": "solve;", "outputs": [{"ename": "NameError", "evalue": "name 'solve' is not defined", "traceback": ["\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m<ipython-input-9-a8150df2eec9>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0msolve\u001b[0m\u001b[1;33m;\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mNameError\u001b[0m: name 'solve' is not defined"], "output_type": "error"}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "print \"WIP=\", WIP", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "x.val", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "B.val", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "II.val", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": null, "cell_type": "code", "source": "", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.6", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement