Skip to content

Commit

Permalink
changed range and added log file
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilienDupont committed Aug 6, 2015
1 parent f532344 commit 746d6b9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
19 changes: 13 additions & 6 deletions facility.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
from gurobipy import *
import math

clients = [[100,200], [150,250], [650, 200], [50, 300]];
logStr = [] # Will contain string of each line of log message

facilities = [[50,50]]; charge = [10];
clients = [[100,200], [150,250], [650, 200], [50, 300]]

facilities = []; charge = []

for i in range(10):
for j in range(10):
facilities.append([i*70, j*50])
charge.append(1)

def mycallback(model, where):
if where == GRB.callback.MESSAGE:
global logStr
logStr.append( model.cbGet(GRB.callback.MSG_STRING) )

def distance(a,b):
dx = a[0] - b[0]
dy = a[1] - b[1]
Expand Down Expand Up @@ -53,10 +60,10 @@ def optimize(clients, facilities, charge, output=False):
m.setObjective( quicksum( charge[j]*x[j] + quicksum(d[(i,j)]*y[(i,j)] for i in range(numClients))
for j in range(numFacilities) ), GRB.MINIMIZE)

m.optimize()
m.optimize(mycallback)

solution1 = [];
solution2 = [];
solution1 = []
solution2 = []

for j in range(numFacilities):
if (x[j].X > .5):
Expand All @@ -67,7 +74,7 @@ def optimize(clients, facilities, charge, output=False):
if (y[(i,j)].X > .5):
solution2.append([i,j])

return [solution1, solution2]
return [solution1, solution2, logStr]

def handleoptimize(jsdict):
if 'clients' in jsdict and 'facilities' in jsdict and 'charge' in jsdict:
Expand Down
46 changes: 40 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ <h2><a href="#demo" name="demo">Live Demo</a></h2>

Cost to build warehouse:
<p>
<input type="range" min = 50000 max = 5000000 step = 500 id="cost" value="1400000" oninput="outputUpdate(value)" class="slider-width">
<output for=cost id=costDisplay>1400000</output> pounds
<input type="range" min = 500000 max = 3000000 step = 500000 id="cost" value="1500000" oninput="outputUpdate(value)" class="slider-width">
<output for=cost id=costDisplay>1500000</output> pounds
<script>
function outputUpdate(value) {
document.querySelector('#costDisplay').value = value;
Expand All @@ -322,6 +322,27 @@ <h2><a href="#demo" name="demo">Live Demo</a></h2>
</div>
<button class="pure-button" onclick="compute()">Compute Warehouse Locations</button>

<p>
<button class="pure-button" onclick="toggle_div()">Gurobi Log</button>
</p>


<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>
function toggle_div() {
var logfile = d3.select('#logfile');
if (logfile.style("display") === "none") {
logfile.style("display", "inline");
} else {
logfile.style("display", "none");
}

}
</script>

<div id=logfile>
</div>

<p style="font-size:8px">
<a name="geolytix">Location data:</a>
<a href="http://geolytix.co.uk/downloads/OpenSupermarkets.zip">Supermarket
Expand All @@ -344,6 +365,9 @@ <h2><a href="#demo" name="demo">Live Demo</a></h2>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>

// Hide Log File intially
d3.select('#logfile').style("display", "none");

//Width and height
var width = 800;
var height = 500;
Expand All @@ -357,6 +381,11 @@ <h2><a href="#demo" name="demo">Live Demo</a></h2>
.attr("width", width)
.attr("height", height);

var logsvg = d3.select("#logfile")
.append("svg")
.attr("width", width)
.attr("height", height);

// Potential sites for facilities
var sites = [[.3*width, .8*height], [.4*width, .3*height], [516.40625, 380.34375],
[486.40625, 55.34375], [766.40625, 179.34375], [728.40625, 439.34375]];
Expand Down Expand Up @@ -548,9 +577,15 @@ <h2><a href="#demo" name="demo">Live Demo</a></h2>
var solution = data['solution'];
var solution1 = solution[0]; // Facilities to open
var solution2 = solution[1]; // Edges to draw
var logMsg = solution[2]; // Log message to display

console.log('solution1', solution1);
console.log('solution2', solution2);
logsvg.selectAll("text")
.data(logMsg)
.enter()
.append("text")
.attr("x", 10)
.attr("y", function(d,i) { return (i+1)*15; })
.text(function(d) { return d; });

var facilities = [];

Expand Down Expand Up @@ -610,8 +645,7 @@ <h2><a href="#demo" name="demo">Live Demo</a></h2>
.attr("y1", function(d) { var loc = vertices[d[0]]; return loc[1]; })
.attr("x2", function(d) { var loc = sites[d[1]]; return loc[0]; })
.attr("y2", function(d) { var loc = sites[d[1]]; return loc[1]; })
.attr("class", function(d) { console.log(d[1]);
var n = solution1.indexOf(d[1]);
.attr("class", function(d) { var n = solution1.indexOf(d[1]);
return "v" + n % 5; })
.attr("stroke-width", 0)
.attr("opacity", 0);
Expand Down

0 comments on commit 746d6b9

Please sign in to comment.