-
Notifications
You must be signed in to change notification settings - Fork 3
/
Optimization.py
31 lines (20 loc) · 986 Bytes
/
Optimization.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
from ortools.algorithms import pywrapknapsack_solver
from tabpy.tabpy_tools.client import Client
#Build the optimization model to solve Knapsack problem
def Optimize_Coverage(Population,Cost, Budget):
solver = pywrapknapsack_solver.KnapsackSolver(
pywrapknapsack_solver.KnapsackSolver.
KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, 'KnapsackExample')
solver.Init(Population, [Cost], [Budget[0]])
solver.Solve()
solution=[False]*len(Population)
for i in range(len(Population)):
if solver.BestSolutionContains(i):
solution[i]=True
return solution
# Connect to TabPy server using the client library
client = Client('http://localhost:9004/')
# Deploy Optimize_Coverage function on TabPy
client.deploy('Optimize_Coverage',
Optimize_Coverage,
'Optimize total coverage by considering resource limitation', override = True)