Skip to content

Instantly share code, notes, and snippets.

View phabee's full-sized avatar

Fabian Leuthold phabee

View GitHub Profile
# Samplescript UKO03.PROG mit MILP + Google OR-Tools für einfaches capacitated Knapsack-Problem
import numpy as np
from ortools.linear_solver import pywraplp
def read_knapsack_problem(file_name):
"""
reads a capacitated knapsack problem instance in a given file and
returns the items as well as the knapsack capacity
# Samplescript UKO03.PROG with k-heuristic with rnd LS for simple capacitated Knapsack Problem
import numpy as np
def read_knapsack_problem(file_name):
"""
Reads a capacitated knapsack problem instance from a specified file
and returns the items along with the knapsack capacity.
:param file_name: The name of the file containing the knapsack instance.
# Samplescript UKO03.PROG with k-heuristic with LS for simple capacitated Knapsack Problem
import numpy as np
def read_knapsack_problem(file_name):
"""
Reads a capacitated knapsack problem instance from a specified file
and returns the items along with the knapsack capacity.
# Samplescript UKO03.PROG mit k-Heuistik für einfaches capacitated Knapsack-Problem
def read_knapsack_problem(file_name):
"""
reads a capacitated knapsack problem instance in a given file and
returns the items as well as the knapsack capacity
:param file_name: the knapsack instance filename
:return: dictionary with item-id as key, tuple with (weight, value)
as value, in addition the knapsack capacity as a separate
# Samplescript UKO03.PROG mit MILP + Google OR-Tools für einfaches capacitated Knapsack-Problem
import pytest
import numpy as np
from ortools.linear_solver import pywraplp
def read_knapsack_problem(file_name):
"""
reads a capacitated knapsack problem instance in a given file and
# Samplescript UKO03.PROG with k-heuristic with LS for simple capacitated Knapsack Problem
import pytest
import numpy as np
def read_knapsack_problem(file_name):
"""
Reads a capacitated knapsack problem instance from a specified file
and returns the items along with the knapsack capacity.
# Samplescript UKO03.PROG with k-heuristic with LS for simple capacitated Knapsack Problem
import pytest
import numpy as np
def read_knapsack_problem(file_name):
"""
Reads a capacitated knapsack problem instance from a specified file
and returns the items along with the knapsack capacity.
NAME: CAP_KS_3
TYPE: CAP_KNAPSACK
COMMENT: Pack 3 items into a knapsack with max_cap=15 (Leuthold)
NUM_ITEMS: 3
KNAPSACK_CAPACITY: 15
ITEMS_ID_WEIGHT_VALUE
1 9.0 10.0
2 7.0 6.0
3 7.0 6.0
EOF
NAME: CAP_KS_2844
TYPE: CAP_KNAPSACK
COMMENT: Pack 2844 items into a knapsack with max_cap=200 (Leuthold)
NUM_ITEMS: 2844
KNAPSACK_CAPACITY: 200
ITEMS_ID_WEIGHT_VALUE
1 41.84 53.84
2 13.32 25.32
3 112.45 124.45
4 105.59 117.59
NAME: CAP_KS_140
TYPE: CAP_KNAPSACK
COMMENT: Pack 140 items into a knapsack with max_cap=50 (Leuthold)
NUM_ITEMS: 140
KNAPSACK_CAPACITY: 50
ITEMS_ID_WEIGHT_VALUE
1 7.95 10.95
2 5.21 8.21
3 16.16 19.16
4 29.52 32.52