Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreyp committed Sep 17, 2020
2 parents e06b839 + fc094f6 commit 09c0afe
Show file tree
Hide file tree
Showing 4 changed files with 747 additions and 1 deletion.
61 changes: 61 additions & 0 deletions moead_framework/problem/combinatorial/mubqp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import numpy as np
from moead_framework.problem.problem import Problem
from moead_framework.solution.one_dimension_solution import OneDimensionSolution


class Mubqp(Problem):

def __init__(self, instance_file):
file = open(instance_file, 'r')
file_content = list(map(str.strip, file.readlines()))
file.close()

file_content = file_content[6:]

definition = file_content[0].split(" ")
self.rho = float(definition[2])
self.m = int(definition[3])
self.n = int(definition[4])
self.d = float(definition[5])
file_content = file_content[2:]

super().__init__(objective_number=self.m)

self.qs = np.zeros((self.m, self.n, self.n))
self.load_qs(file_content)

def f(self, function_id, solution):
fit = 0

for i in range(self.n):
if solution[i] == 1:
for j in range(i+1):
if solution[j] == 1:
fit += self.qs[function_id][i][j]

return fit

def generate_random_solution(self, evaluate=True):
return self.generate_solution(array=np.random.randint(0, 2, self.n).tolist()[:], evaluate=evaluate)

def generate_solution(self, array, evaluate=True):
x = OneDimensionSolution(np.array(array, dtype=int))

for j in range(self.function_numbers):
if evaluate:
x.F.append(self.f(j, x.solution))
else:
x.F.append(None)

return x

def load_qs(self, array):
line = 0
for i in range(self.n):
for j in range(self.n):
s = array[line].split(" ")
line += 1
for n in range(self.m):
self.qs[n][i][j] = int(s[n])
pass

Loading

0 comments on commit 09c0afe

Please sign in to comment.