Skip to content

Commit

Permalink
got aggregated worst and mode worst option
Browse files Browse the repository at this point in the history
  • Loading branch information
plyh committed Apr 19, 2019
1 parent 95c2c75 commit ce8ac58
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
22 changes: 14 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import os
import time
import zipfile

Expand All @@ -16,7 +17,7 @@
ALLOWED_EXTENSIONS = set(['zip'])

app = Flask(__name__)
app.config['SECRET_KEY'] = ''
app.config['SECRET_KEY'] = 'aaaa'
CORS(app)


Expand All @@ -37,7 +38,7 @@ def upload_file():
if 'zip_file' not in request.files:
flash('No file part')
return redirect(request.url)

# filename = os.path.join(DATA_DIR, 'full_sample_%d_for_students.csv' % day)
file = request.files['zip_file']
# if user does not select file, browser also
# submit a empty part without filename
Expand All @@ -53,18 +54,20 @@ def upload_file():

radius = float(request.form['radius'])
num_cars = request.form['num_cars']

multi_method = request.form['multi-method']
time_varying = request.form.get('time-varying')

DATA_DIR = os.path.join(UPLOAD_FOLDER, filename[:-4])
outfile = os.path.join(UPLOAD_FOLDER, 'sol.csv')
if num_cars == '':
num_cars = 15
optimize(DATA_DIR, radius, int(num_cars), outfile)
optimize(DATA_DIR, radius, int(num_cars), outfile, multi_method, time_varying)

# return render_template('index.html')
return redirect(url_for('allocation_file', filename='sol.csv'))


def optimize(data_dir, radius, num_cars, outfile):
def optimize(data_dir, radius, num_cars, outfile, multi_method, time_varying = None):
t0 = time.time()

data_files = os.listdir(data_dir)
Expand All @@ -89,9 +92,12 @@ def optimize(data_dir, radius, num_cars, outfile):
df = solve.load_dataset(data_dir, len(data_files), grids, regions, distances) # Load all data
worst_days = solve.find_worst_day_by_grid(df, grids)
wd_incidences = solve.get_worst_day_incidences(df, grids, worst_days)
mode = wd_incidences.day.mode().values[0]
df = df[df.day==mode]

if multi_method == "mode":
mode = wd_incidences.day.mode().values[0]
df = df[df.day==mode]
elif multi_method == "aggregated":
df = wd_incidences

print("Finding overlaps in incidence times...")
clashes = solve.find_clashes(df)

Expand Down
9 changes: 0 additions & 9 deletions solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,13 @@ def allocate(grids, assigned_bases, clashes, num_cars=15, outfile='sol.csv'):

I = len(assigned_bases.index) #number of tasks
J = num_cars #number of cars
# K = 6 #number of base stations

# Decision variables
x_ij = {}
# y_jk = {}
# z_ik = pd.read_csv('incident_2.csv')
for i in range(I):
for j in range(J):
x_ij[i, j] = mdl.binary_var(name='x[%d,%d]' % (i, j))

# y_jk = {}
# for j in range(I):
# for k in range(J):
# y_jk[j, k] = mdl.binary_var(name='y[%d,%d]' % (j, k))


# Objective function
obj = mdl.linear_expr()
for i in range(I):
Expand Down
9 changes: 9 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ <h2 class="subtitle">
<input class="input" type="text" placeholder="15" name="num_cars">
<span>Available cars</span>
</div>
<div class="column">
<span><b>Multiple Dataset Method:</b></span><br>
<input type="radio" name="multi-method" value="mode" checked> Mode Worst <br>
<input type="radio" name="multi-method" value="aggregated"> Aggregated Worst <br>
</div>
<div class="column">
<span><b>X-Factor:</b></span><br>
<input type="checkbox" name="time-varying" value="time-varying" checked> Time-Varying Bases <br>
</div>
<div class="column">
<input class="button" type="submit" value="Optimize" />
</div>
Expand Down

0 comments on commit ce8ac58

Please sign in to comment.