-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
747 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.