{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "srand(1);\n", "using Distributions\n", "m = 5;\n", "n = 24;\n", "SCALE = 10000;\n", "B = rand(LogNormal(8), m) + 10000;\n", "B = round(B, 3);\n", "\n", "P_ad = rand(m);\n", "P_time = rand(1,n);\n", "P = P_ad * P_time;\n", "\n", "T = sin(linspace(-2*pi/2, 2*pi-2*pi/2, n)) * SCALE;\n", "T += -minimum(T) + SCALE;\n", "c = rand(m);\n", "c *= 0.6*sum(T)/sum(c);\n", "c = round(c, 3);\n", "R = [rand(LogNormal(minimum(c)/c[i]), 1) for i=1:m];" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Form and solve the optimal advertising problem.\n", "using Convex, SCS;\n", "D = Variable(m, n);\n", "Si = [min(R[i]*P[i,:]*D[i,:]', B[i]) for i=1:m];\n", "problem = maximize(sum(Si),\n", " [D >= 0, sum(D,1)' <= T, sum(D,2) >= c]);\n", "solve!(problem, SCSSolver(verbose=0));" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n" ], "text/html": [ "\n", "\n" ], "text/plain": [ "Plot(...)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Plot traffic.\n", "using Gadfly\n", "plot(x=1:length(T), y=T, Geom.line, Guide.XLabel(\"Hour\"), Guide.YLabel(\"Traffic\"))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n" ], "text/html": [ "\n", "\n" ], "text/plain": [ "Plot(...)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Plot P.\n", "spy(P)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n" ], "text/html": [ "\n", "\n" ], "text/plain": [ "Plot(...)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Plot optimal D.\n", "spy(evaluate(D))" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 0.3.9", "language": "julia", "name": "julia-0.3" }, "language_info": { "name": "julia", "version": "0.3.9" } }, "nbformat": 4, "nbformat_minor": 0 }