Skip to content

Commit

Permalink
Merge pull request #17 from fzsun/vue_documentation
Browse files Browse the repository at this point in the history
commented vue files, made csv creation dynamic based on horizon number
  • Loading branch information
rbs333 authored May 5, 2019
2 parents 84b1861 + 908edb3 commit a400cac
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 129 deletions.
Empty file.
9 changes: 9 additions & 0 deletions algorithm/tsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
Created on Sat Jun 30 21:01:11 2018
@author: Fangzhou Sun
This file is intended to show an example of how Gurobipy can be used
to create optimization algorithms in an object oriented way. In structure,
it is very similar to s_bfl.py and should be a starting point for writing
additional optimizations. Writting optimizations in an object oriented way
makes it much easier to utilize the code within a project because we can
simply import the class into another python file and create an instance of
the class to run the optimization.
"""
import numpy as np
from scipy.spatial import distance_matrix
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
export default {
data() {
return {
//Members of the team, including name, image, email, and small bio
team_members: [
{
name: "Dr. Subhash Sarin",
Expand Down
168 changes: 43 additions & 125 deletions frontend/src/components/Csv_Formatter.vue
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
<template>
<vue-json-to-csv :json-data="op_response_csv"
csv-title="s_bfl_optimization"
:labels="{
0: { title: '' },
1: { title: '' },
2: { title: '' },
3: { title: '' },
4: { title: '' },
5: { title: '' },
6: { title: '' },
7: { title: '' },
8: { title: '' },
9: { title: '' },
10: { title: '' },
11: { title: '' },
12: { title: '' },
13: { title: '' },
14: { title: '' },
15: { title: '' },
16: { title: '' },
17: { title: '' },
18: { title: '' },
19: { title: '' },
20: { title: '' },
21: { title: '' },
22: { title: '' },
23: { title: '' },
24: { title: '' },
25: { title: '' },
26: { title: '' },
27: { title: '' },
28: { title: '' },
29: { title: '' },
30: { title: '' },
31: { title: '' }
}">
:labels="total_labels">

<button id="optimization_csv_button" class="button is-success" hidden="true">
Download Full Results
</button>
Expand All @@ -50,10 +18,16 @@ export default {
},
data() {
return {
op_response_csv: [],
op_response_csv: [],
total_labels: {}
}
},
methods: {
/*
CSV file format does not support writing to multiple
tabs (like a spredsheet can), for this reason one large
csv file is created with added rows as spacers.
*/
generateCsv(data, refinery_location) {
var csv_index = 0;
Expand All @@ -80,6 +54,12 @@ export default {
var upperbound_equip_proc_rate = params.upperbound_equip_proc_rate;
var upperbound_equip_proc_rate_jit = params.upperbound_equip_proc_rate_jit;
var upperbound_inventory = params.upperbound_inventory;
var horizon = data.summary.others.num_weeks_horizon;
var n;
for (n = 0; n < (horizon + 6); n++) {
this.total_labels[n] = {title: '' };
}
//sysnum, configuration, seed, refinery coords chart
this.op_response_csv[csv_index++] = ["sysnum",
Expand Down Expand Up @@ -116,37 +96,13 @@ export default {
//harvested + demand
this.op_response_csv[csv_index++] = ["",
"week 0",
"week 1",
"week 2",
"week 3",
"week 4",
"week 5",
"week 6",
"week 7",
"week 8",
"week 9",
"week 10",
"week 11",
"week 12",
"week 13",
"week 14",
"week 15",
"week 16",
"week 17",
"week 18",
"week 19",
"week 20",
"week 21",
"week 22",
"week 23",
"week 24",
"week 25",
"week 26"];
this.op_response_csv[csv_index] = [""];
for (n = 0; n < (horizon + 1); n++) {
this.op_response_csv[csv_index][this.op_response_csv[csv_index].length] = "week " + n;
}
csv_index++;
var total_index = csv_index;
var n;
for (n = 0; n < harvested[0].length; n++) {
this.op_response_csv[csv_index] = ["farm " + n];
Expand All @@ -159,7 +115,7 @@ export default {
this.op_response_csv[csv_index] = ["week total: "];
var m;
for (m = 1; m <= 27; m++) {
for (m = 1; m <= (horizon + 1); m++) {
var p;
var total = 0;
for (p = total_index; p < csv_index; p++) {
Expand Down Expand Up @@ -194,37 +150,18 @@ export default {
this.op_response_csv[csv_index++] = [];
this.op_response_csv[csv_index++] = [];
this.op_response_csv[csv_index++] = ["farm num",
this.op_response_csv[csv_index] = ["farm num",
"farm lat",
"farm lng",
"ssl num",
"farm to ssl cost ($/Mg)",
"week 1 (Mg)",
"week 2",
"week 3",
"week 4",
"week 5",
"week 6",
"week 7",
"week 8",
"week 9",
"week 10",
"week 11",
"week 12",
"week 13",
"week 14",
"week 15",
"week 16",
"week 17",
"week 18",
"week 19",
"week 20",
"week 21",
"week 22",
"week 23",
"week 24",
"week 25",
"week 26"];
"farm to ssl cost ($/Mg)"];
var q;
for (q = 0; q < (horizon); q++) {
this.op_response_csv[csv_index][this.op_response_csv[csv_index].length] = "week " + (q + 1);
}
csv_index++;
farm_ssl = false;
farm_index = csv_index;
}
Expand Down Expand Up @@ -252,38 +189,17 @@ export default {
this.op_response_csv[csv_index++] = [];
this.op_response_csv[csv_index++] = [];
this.op_response_csv[csv_index++] = ["ssl num",
this.op_response_csv[csv_index] = ["ssl num",
"ssl lat",
"ssl lng",
"ssl to ref cost ($/Mg)",
"cost to build ssl ($)",
"ssl type",
"week 1 (Mg)",
"week 2",
"week 3",
"week 4",
"week 5",
"week 6",
"week 7",
"week 8",
"week 9",
"week 10",
"week 11",
"week 12",
"week 13",
"week 14",
"week 15",
"week 16",
"week 17",
"week 18",
"week 19",
"week 20",
"week 21",
"week 22",
"week 23",
"week 24",
"week 25",
"week 26"];
"ssl type"];
var q;
for (q = 0; q < (horizon); q++) {
this.op_response_csv[csv_index][this.op_response_csv[csv_index].length] = "week " + (q + 1);
}
csv_index++;
ssl_ref = false;
ssl_index = csv_index;
Expand Down Expand Up @@ -381,19 +297,21 @@ export default {
this.op_response_csv[csv_index++] = [];
this.op_response_csv[csv_index++] = [];
this.fill_undefined();
this.fill_undefined(horizon);
document.getElementById('optimization_csv_button').hidden = false;
},
fill_undefined() {
//Fill unused column elemenets
fill_undefined(horizon) {
var k;
for (k = 0; k < this.op_response_csv.length; k++) {
var m;
for (m = 0; m < 32; m++) {
for (m = 0; m < (horizon + 6); m++) {
if (this.op_response_csv[k][m] == null)
this.op_response_csv[k][m] = "";
}
var obj = {};
for (m = 0; m < 32; m++) {
for (m = 0; m < (horizon + 6); m++) {
obj[m] = this.op_response_csv[k][m];
}
this.op_response_csv[k] = obj;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ export default {
height: 3rem;
margin: .25rem .5rem;
}
</style>
</style>
16 changes: 14 additions & 2 deletions frontend/src/components/Map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default {
})
},
//Add points to map
//Called when user clicks on map to add pin
addPushpin() {
var ref = this;
google.maps.event.addListener(this.map, 'click', function(event) {
Expand All @@ -113,6 +113,8 @@ export default {
});
},
//Place specific marker on map, given the location and name. Give different
//colors and place in different arrays based on which location type it is
placeMarker(location, locationname) {
var ref = this;
if (this.name == 'Refinery') {
Expand Down Expand Up @@ -186,7 +188,8 @@ export default {
this.farmsCounter = this.farmsCounter + 1;
}
},
//Delete marker from map and from it's corresponding array
delMarker(id, type) {
if (type == "refinery") {
var marker = this.refineryMarker;
Expand Down Expand Up @@ -215,6 +218,7 @@ export default {
this.placeMarker(myLatlng, farmname);
},
//Put address on map and in array when given a specific address for a location
submitAddress() {
var address = this.address;
var addressName = this.addressName;
Expand Down Expand Up @@ -246,6 +250,14 @@ export default {
//Submit locations to background for optimization
submitLocations() {
/*
Because the backend code relies on the position of elements
added to the coordinate arrays, we cannot simply delete
entries because this would mess up the order. Therefore,
we instead null the item that was deleted before submission
and then use this function to remove the null entries at
the end to maintain proper ordering.
*/
var filteredFarm = this.farms.filter(function (el) {
return el != null;
});
Expand Down
16 changes: 15 additions & 1 deletion frontend/src/components/S_BFLS.vue
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ export default {
this.customForm = false;
this.showOptButton = false;
},
//Add "routes" to map (lines between one point and another) to give a better
//view of what farm goes where.
parseApplyRoutes(response) {
var len = response.summary.allocation_from_farm.length;
var refinery = {"lat": this.model.refinery_location[0], "lng": this.model.refinery_location[1]}
Expand All @@ -422,6 +425,9 @@ export default {
this.$refs.map.addRoutes(route);
}
},
//Get info from the map and send all information to the backend,
//updating the map and solution fields when the optimization finishes.
optimize(event) {
var mapInfo = this.$refs.map.submitLocations();
Expand All @@ -434,7 +440,13 @@ export default {
this.model.input_format = mapInfo.mode;
this.model.refinery_location = mapInfo.refinery_location;
this.model.new_input = this.new_input;
console.log(this.model);
/*
axios is a 3rd party module that allows us to communicate with the backend API.
In this case, we issue a post method and provide axios the port our server is running
on (http://localhost:5000) with the route we want to access (/s-bfls/) plus the data we
want to send it (this.model). We then instruct axios what to do onec it gets a response
from the backend server sends in the .then() section.
*/
axios
.post('http://localhost:5000/s-bfls/', this.model)
.then(response => {
Expand All @@ -453,6 +465,8 @@ export default {
}
},
//Display the pie chart and relative costs when the optimization/simulation finishes
show_results(data) {
this.chart_info = {}; this.chart_data = [];
Expand Down
Loading

0 comments on commit a400cac

Please sign in to comment.