This repository has been archived by the owner on Aug 25, 2022. It is now read-only.
forked from hughneerhut/Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
56 lines (41 loc) · 1.39 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import numpy as np
from pyswarm import pso
# Group 14 - Logistical optomisation problem
# Step 1. Import delivery order list from CSV into an array
# Step 2: Define the objective function
# We will use distance as the main factor for lowering emission output
def weight(x, *args):
H, d, t = x
B, rho, E, P = args
return rho*2*np.pi*d*t*np.sqrt((B/2)**2 + H**2)
# Step 3: Define contraints
# For our project the constraint functions will be volume of orders and weight of orders per truck
def yield_stress(x, *args):
H, d, t = x
B, rho, E, P = args
return (P*np.sqrt((B/2)**2 + H**2))/(2*t*np.pi*d*H)
def buckling_stress(x, *args):
H, d, t = x
B, rho, E, P = args
return (np.pi**2*E*(d**2 + t**2))/(8*((B/2)**2 + H**2))
def deflection(x, *args):
H, d, t = x
B, rho, E, P = args
return (P*np.sqrt((B/2)**2 + H**2)**3)/(2*t*np.pi*d*H**2*E)
def constraints(x, *args):
strs = yield_stress(x, *args)
buck = buckling_stress(x, *args)
defl = deflection(x, *args)
return [100 - strs, buck - strs, 0.25 - defl]
# Define the other parameters
B = 60 # inches
rho = 0.3 # lb/in^3
E = 30000 # kpsi (1000-psi)
P = 66 # kip (1000-lbs, force)
args = (B, rho, E, P)
# Define the lower and upper bounds for H, d, t, respectively
lb = [10, 1, 0.01]
ub = [30, 3, 0.25]
xopt, fopt = pso(weight, lb, ub, f_ieqcons=constraints, args=args)
print(xopt)
print(fopt)