Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4070c18

Browse files
committedJan 23, 2014
Initial commit
1 parent 60b46f4 commit 4070c18

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
 

‎genetic.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require_relative('item.rb')
2+
require_relative('knapsack.rb')
3+
4+
if ARGV.length > 0
5+
num_items = ARGV[0].chomp.to_i
6+
num_knapsacks = ARGV[1].chomp.to_i
7+
num_generations = ARGV[2].chomp.to_i
8+
end
9+
10+
items = []
11+
knapsacks = []

‎item.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Item
2+
3+
attr_accessor :weight, :value
4+
5+
def initialize(weight, value)
6+
@weight = weight
7+
@value = value
8+
end
9+
10+
end

‎knapsack.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Knapsack
2+
3+
@items = []
4+
5+
def add_item(item)
6+
@items << item
7+
end
8+
9+
def total_weight
10+
total = 0.0
11+
@items.each do |item|
12+
total += item.weight
13+
end
14+
total
15+
end
16+
17+
end

0 commit comments

Comments
 (0)
Please sign in to comment.