-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (45 loc) · 1.66 KB
/
main.py
File metadata and controls
55 lines (45 loc) · 1.66 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Copyright 2018(c). All rights reserved.
#
# This is free software; you can do what the LICENCE file allows you to.
# Author: Ing. Oraldo Jacinto Simon
from __future__ import (division as _py3_division,
print_function as _py3_print,
absolute_import as _py3_abs_import)
from texttable import Texttable
from knapsack import knapsack as Knapsack
# WTS = [1,3,4,5]
# VALS = [1,4,5,7]
WTS = [1,2,5,6,7]
VALS = [1,6,18,22,28]
# WTS = [2,3,4,5]
# VALS = [3,4,5,6]
CAPACITY = 11
class Main(object):
def __init__(self):
'''A practical exercise of the knapsack problem solved with dynamic
programming
'''
print ('''********************Knapsack problem************************
Author: Oraldo Jacinto Simon
Professor: M.I. Jesus Roberto López Santillán
''')
knapsack_obj = Knapsack(VALS, WTS, CAPACITY)
table_result, res = knapsack_obj.dp_knapsack()
table = Texttable()
table.set_cols_align(["c" for e in range(CAPACITY+1)])
rows = []
head = [index for index in range(CAPACITY+1)]
rows.append(head)
[str(rows.append(e)) for e in table_result]
table.add_rows(rows)
print("values = %s" % VALS)
print("weights = %s" % WTS)
print("capacity = %s" % CAPACITY)
print(table.draw() + "\n")
print("Solución: %d" % res)
path = knapsack_obj.print_path()
print("Entre las mochilas de la solución se encuentran: %s" % str(path))
Main()