Use np alias for numpy
This commit is contained in:
parent
1be7ba0f55
commit
323c6aad61
|
@ -18,18 +18,11 @@ from scipy.optimize import linprog
|
||||||
from scipy.ndimage.interpolation import shift
|
from scipy.ndimage.interpolation import shift
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy import array
|
|
||||||
from numpy import zeros
|
|
||||||
from numpy import append
|
|
||||||
from numpy import vstack
|
|
||||||
from numpy import concatenate
|
|
||||||
from numpy import put
|
|
||||||
from numpy import roll
|
|
||||||
|
|
||||||
|
|
||||||
def shift(arr, steps, val=0):
|
def shift(arr, steps, val=0):
|
||||||
res_arr = roll(arr, steps)
|
res_arr = np.roll(arr, steps)
|
||||||
put(res_arr, range(steps), val)
|
np.put(res_arr, range(steps), val)
|
||||||
|
|
||||||
return res_arr
|
return res_arr
|
||||||
|
|
||||||
|
@ -94,18 +87,14 @@ class DynamicAllocationLinearProgram(object):
|
||||||
# An array of values representing right side of equation,
|
# An array of values representing right side of equation,
|
||||||
# left side is represented by row of `equality_constraint_matrix`
|
# left side is represented by row of `equality_constraint_matrix`
|
||||||
# matrix
|
# matrix
|
||||||
self.equality_constraint_vector = array([])
|
self.equality_constraint_vector = np.array([])
|
||||||
|
|
||||||
# Specify boundaries of each x in the next format (min, max). Use
|
# Specify boundaries of each x in the next format (min, max). Use
|
||||||
# None for one of min or max when there is no bound.
|
# None for one of min or max when there is no bound.
|
||||||
self.bounds = array([])
|
self.bounds = np.array([])
|
||||||
|
|
||||||
self._initialize_equation(disks, spaces)
|
self._initialize_equation(disks, spaces)
|
||||||
|
|
||||||
print '*' * 30
|
|
||||||
print self.equality_constraint_matrix
|
|
||||||
print self.objective_function_coefficients
|
|
||||||
|
|
||||||
def solve(self):
|
def solve(self):
|
||||||
solution = linprog(
|
solution = linprog(
|
||||||
self.objective_function_coefficients,
|
self.objective_function_coefficients,
|
||||||
|
@ -120,7 +109,7 @@ class DynamicAllocationLinearProgram(object):
|
||||||
for d in disks:
|
for d in disks:
|
||||||
# Initialize constraints, each row in the matrix should
|
# Initialize constraints, each row in the matrix should
|
||||||
# be equal to size of the disk
|
# be equal to size of the disk
|
||||||
self.equality_constraint_vector = append(self.equality_constraint_vector, d.size)
|
self.equality_constraint_vector = np.append(self.equality_constraint_vector, d.size)
|
||||||
|
|
||||||
# Initialize the matrix
|
# Initialize the matrix
|
||||||
# In case of 2 spaces and 3 disks the result should be:
|
# In case of 2 spaces and 3 disks the result should be:
|
||||||
|
@ -139,7 +128,7 @@ class DynamicAllocationLinearProgram(object):
|
||||||
# For each space x (size of the space) is represented
|
# For each space x (size of the space) is represented
|
||||||
# for each disk as separate variable, so for each
|
# for each disk as separate variable, so for each
|
||||||
# disk we have len(spaces) * len(disks) sizes
|
# disk we have len(spaces) * len(disks) sizes
|
||||||
equality_matrix_row = zeros(len(spaces) * len(disks))
|
equality_matrix_row = np.zeros(len(spaces) * len(disks))
|
||||||
self._init_objective_function_coefficient(len(spaces) * len(disks))
|
self._init_objective_function_coefficient(len(spaces) * len(disks))
|
||||||
|
|
||||||
# Set first len(spaces) elements to 1
|
# Set first len(spaces) elements to 1
|
||||||
|
@ -167,4 +156,4 @@ class DynamicAllocationLinearProgram(object):
|
||||||
self.objective_function_coefficients = [-1] * size
|
self.objective_function_coefficients = [-1] * size
|
||||||
|
|
||||||
def _add_bound(self, min_, max_):
|
def _add_bound(self, min_, max_):
|
||||||
append(self.bounds.append, (min_, max_))
|
np.append(self.bounds, (min_, max_))
|
||||||
|
|
Loading…
Reference in New Issue