Skip to content

Commit

Permalink
first shot
Browse files Browse the repository at this point in the history
  • Loading branch information
aiswaryasankartest committed Apr 24, 2017
0 parents commit f3d8780
Show file tree
Hide file tree
Showing 55 changed files with 2,570,807 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions CostGreedy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
100
100
3
0
A; 0; 1; 1; 0
B; 1; 99; 99; 0
C; 2; 100; 100; 200
7 changes: 7 additions & 0 deletions WeightGreedy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
100
100
3
0
A; 0; 1; 100; -10
B; 1; 99; 100; -10
C; 2; 100; 0; 100
6 changes: 6 additions & 0 deletions easy2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
100
100
2
0
somewhat_heavy_rock; 0; 90; 1; 5
gem_on_sale; 1; 2; 50; 200
10 changes: 10 additions & 0 deletions easy3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
100
100
3
3
somewhat_heavy_rock; 0; 90; 1; 5
gem_on_sale; 1; 2; 50; 200
small_present; 2; 1; 20; 40
0, 1
1, 2
0, 2
11 changes: 11 additions & 0 deletions easy4
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
100
100
3
4
somewhat_heavy_rock; 0; 90; 1; 5
gem_on_sale; 1; 2; 50; 200
small_present; 2; 1; 20; 40
1, 10
2, 11
3, 12
1, 2, 3, 4
7 changes: 7 additions & 0 deletions example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
100
100
2
1
heavy_worthless_rock; 0; 99; 1; 5
gem_on_sale; 1; 2; 50; 200
0, 1
158 changes: 158 additions & 0 deletions generate_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#!/usr/bin/env python
from __future__ import division
import argparse
import random
import numpy as np

def generate_items():
items = []
classes = set()
maxWeight = 0
maxCost = 0
for i in range(20):
item_name = "Item " + str(i)
class_name = random.randint(0, 199999)
weight = random.randint(0, 100000)
cost = random.randint(0, 100000)
resale = check_profit_positive(cost, random.randint(0, 100000))
item_string = "{}; {}; {}; {}; {}".format(item_name, class_name, weight, cost, resale)
items.append(item_string)
classes.add(class_name)

if maxWeight < weight:
maxWeight = weight
if maxCost < cost:
maxCost = cost
return (items, list(classes), maxWeight, maxCost)

def check_profit_positive(cost, resale):
while resale < cost:
resale = random.randint(0, 100000)
return resale

def write_output(filename, items_chosen):
with open(filename, "w") as f:
for i in items_chosen:
f.write("{0}\n".format(i))

#3 1's, 20 2's, 12 3's, 36 4's = 71
def generate_items_only_one_class_chosen():
items = []
classes = set()

maxWeight = 0
maxCost = 0

for i in range(3): #Three items of class 1
item_name = "Item " + str(i)
class_name = 1
weight = random.randint(0, 100000)
cost = random.randint(0, 100000)
resale = check_profit_positive(cost, random.randint(0, 100000))
item_string = "{}; {}; {}; {}; {}".format(item_name, class_name, weight, cost, resale)
items.append(item_string)
classes.add(class_name)

if maxWeight < weight:
maxWeight = weight
if maxCost < cost:
maxCost = cost

for i in range(20): #Twenty items of class 2
item_name = "Item " + str(i + 3)
class_name = 2
weight = random.randint(0, 100000)
cost = random.randint(0, 100000)
resale = check_profit_positive(cost, random.randint(0, 100000))
item_string = "{}; {}; {}; {}; {}".format(item_name, class_name, weight, cost, resale)
items.append(item_string)
classes.add(class_name)

if maxWeight < weight:
maxWeight = weight
if maxCost < cost:
maxCost = cost

for i in range(12): #Twelve items of class 3
item_name = "Item " + str(i + 23)
class_name = 3
weight = random.randint(0, 100000)
cost = random.randint(0, 100000)
resale = check_profit_positive(cost, random.randint(0, 100000))
item_string = "{}; {}; {}; {}; {}".format(item_name, class_name, weight, cost, resale)
items.append(item_string)
classes.add(class_name)

if maxWeight < weight:
maxWeight = weight
if maxCost < cost:
maxCost = cost

for i in range(36): #36 items of class 4
item_name = "Item " + str(i + 35)
class_name = 4
weight = random.randint(0, 100000)
cost = random.randint(0, 100000)
resale = check_profit_positive(cost, random.randint(0, 100000))
item_string = "{}; {}; {}; {}; {}".format(item_name, class_name, weight, cost, resale)
items.append(item_string)
classes.add(class_name)

if maxWeight < weight:
maxWeight = weight
if maxCost < cost:
maxCost = cost

for i in range(29): #100 - 71 = 29
item_name = "Item " + str(i + 71)
class_name = i + 71
weight = random.randint(0, 100000)
cost = random.randint(0, 100000)
resale = check_profit_positive(cost, random.randint(0, 100000))
item_string = "{}; {}; {}; {}; {}".format(item_name, class_name, weight, cost, resale)
items.append(item_string)
classes.add(class_name)

if maxWeight < weight:
maxWeight = weight
if maxCost < cost:
maxCost = cost

return (items, list(classes), maxWeight, maxCost)

def createConstraints(classes):
# Generate random number of elements for the constraint
allConstraints = []
for i in range(8):
num = np.random.randint(2,10)
a = [classes[np.random.randint(0, len(classes))] for i in range(num)]
allConstraints.append(a)

constraints_formatted = []
for constraint in allConstraints:
constraints_formatted.append(', '.join(map(str, constraint)))
return constraints_formatted

if __name__ == "__main__":

parser = argparse.ArgumentParser(description="PickItems solver.")
parser.add_argument("output_file", type=str, help="____.out")
args = parser.parse_args()

items_chosen, classes_chosen, maxWeight, maxCost = generate_items()
#items_chosen, classes_chosen, maxWeight, maxCost = generate_items_only_one_class_chosen()
constraints = createConstraints(classes_chosen)

pounds = [maxWeight]
dollars = [maxCost]
num_items = [20]
num_constraints = [8]

setup_values = pounds + dollars + num_items + num_constraints
write_to_file = setup_values + items_chosen + constraints

for i in range(5):
random.shuffle(constraints)
write_to_file += ["", "New constraint " + str(i)] + constraints

write_output(args.output_file, write_to_file)
50 changes: 50 additions & 0 deletions knapsack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## Aiswarya Sankar
## 4/21/17
## Knapsack Implementation

import numpy as np

def knapsack():
noItems = int(input())
totalWeight = int(input())
weights = int(input().split(','))
values = int(input().split(','))


table = np.zeros(totalWeight * noItems).reshape((totalWeight, noItems))
for item in noItems:
for weight in totalWeight:
pass


knapsack()



#code
import numpy as np

def knapsack():
numTests = input()
for num in numTests:
noItems = int(input())
totalWeight = int(input())
weights = input().split(' ')
values = input().split(' ')

table = []

for i in range(noItems):
table[i][0] = 0
for j in range(totalWeight):
table[0][j] = 0

for i in range(noItems):
for j in range(totalWeight):
if weights[j] + table[i][j-1] > totalWeight:
table[i][j] = table[i][j-1]
else:
table[i][j] = max(table[i-1][j-weights[j]] + value[j], table[i-1][j])
return table[noItems][totalWeight]

knapsack()
9 changes: 9 additions & 0 deletions maxProfit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
5
5
4
1
Item1; 2; 2; 2; 10
Item2; 2; 3; 3; 10
Item3; 1; 5; 10; 1
Item4; 1; 5; 10; 1
1, 2
9 changes: 9 additions & 0 deletions minCostTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
5
5
4
1
Item1; 2; 2; 2; 1
Item2; 2; 3; 3; 1
Item3; 1; 5; 10; 1
Item4; 1; 5; 10; 1
1, 2
8 changes: 8 additions & 0 deletions numItemsTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
5
5
3
1
Item1; 2; 2; 2; 1
Item2; 2; 3; 3; 1
Item3; 1; 5; 5; 1
1, 2
1 change: 1 addition & 0 deletions o.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
82 changes: 82 additions & 0 deletions out
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
98294
98270
20
8
Item 0; 45727; 63940; 26022; 96465
Item 1; 182050; 4706; 86454; 97068
Item 2; 72054; 50924; 91329; 97618
Item 3; 139740; 30198; 6622; 54366
Item 4; 887; 66040; 27617; 29627
Item 5; 161899; 98294; 12259; 42096
Item 6; 158273; 30005; 82965; 92575
Item 7; 57402; 23286; 29058; 86304
Item 8; 49895; 98107; 40745; 41927
Item 9; 12351; 78798; 7666; 76225
Item 10; 198597; 34365; 22121; 94027
Item 11; 151413; 6748; 79992; 99981
Item 12; 52337; 88667; 66612; 80544
Item 13; 63064; 87849; 75066; 94733
Item 14; 176764; 76031; 9802; 49767
Item 15; 73601; 86192; 30600; 79100
Item 16; 106649; 35134; 82336; 82905
Item 17; 181691; 79490; 66521; 87161
Item 18; 139823; 48882; 32872; 53729
Item 19; 43291; 13058; 98270; 99689
139740, 176764, 182050
45727, 57402
106649, 151413
139823, 72054, 106649
63064, 63064, 198597
45727, 49895, 12351, 158273, 49895, 57402, 139740
43291, 57402, 176764, 43291, 182050, 45727, 49895
181691, 106649, 887, 198597

New constraint 0
43291, 57402, 176764, 43291, 182050, 45727, 49895
139823, 72054, 106649
45727, 57402
139740, 176764, 182050
181691, 106649, 887, 198597
63064, 63064, 198597
106649, 151413
45727, 49895, 12351, 158273, 49895, 57402, 139740

New constraint 1
43291, 57402, 176764, 43291, 182050, 45727, 49895
139740, 176764, 182050
106649, 151413
181691, 106649, 887, 198597
139823, 72054, 106649
45727, 49895, 12351, 158273, 49895, 57402, 139740
63064, 63064, 198597
45727, 57402

New constraint 2
181691, 106649, 887, 198597
45727, 49895, 12351, 158273, 49895, 57402, 139740
43291, 57402, 176764, 43291, 182050, 45727, 49895
106649, 151413
63064, 63064, 198597
45727, 57402
139823, 72054, 106649
139740, 176764, 182050

New constraint 3
45727, 49895, 12351, 158273, 49895, 57402, 139740
139740, 176764, 182050
45727, 57402
63064, 63064, 198597
181691, 106649, 887, 198597
139823, 72054, 106649
43291, 57402, 176764, 43291, 182050, 45727, 49895
106649, 151413

New constraint 4
106649, 151413
139823, 72054, 106649
181691, 106649, 887, 198597
63064, 63064, 198597
43291, 57402, 176764, 43291, 182050, 45727, 49895
45727, 57402
139740, 176764, 182050
45727, 49895, 12351, 158273, 49895, 57402, 139740
1 change: 1 addition & 0 deletions out1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
8 changes: 8 additions & 0 deletions phase1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Aiswarya Sankar
## 4/16/2017
## Phase1.py

## This program will enforce that each constraint is satisfied in the problem. This means that you will never have a variable in one of the sets that you actually can't choose any values from.

def check_constraints():

Binary file added problem1.in.pdf
Binary file not shown.
Loading

0 comments on commit f3d8780

Please sign in to comment.