[new] Implement container
This commit is contained in:
@@ -1,19 +1,24 @@
|
||||
import math
|
||||
import random
|
||||
import matplotlib.pyplot as plt
|
||||
from model.base_model import Model
|
||||
|
||||
class SimAnneal(Model):
|
||||
def __init__(self, coords, T=-1, alpha=-1, stopping_T=-1):
|
||||
super().__init__(coords)
|
||||
def __init__(self, T=-1, alpha=-1, stopping_T=-1):
|
||||
super().__init__()
|
||||
|
||||
self.iteration = 0
|
||||
|
||||
self.T = math.sqrt(self.N) if T == -1 else T
|
||||
self.T_save = self.T # save inital T to reset if batch annealing is used
|
||||
self.T = T
|
||||
self.alpha = 0.995 if alpha == -1 else alpha
|
||||
self.stopping_temperature = 1e-8 if stopping_T == -1 else stopping_T
|
||||
|
||||
def init(self, coords):
|
||||
super().init(coords)
|
||||
|
||||
if (self.T == -1):
|
||||
self.T = math.sqrt(self.N)
|
||||
self.T_save = self.T # save inital T to reset if batch annealing is used
|
||||
|
||||
def initial_solution(self):
|
||||
"""
|
||||
Greedy algorithm to get an initial solution (closest-neighbour).
|
||||
|
||||
@@ -2,15 +2,16 @@ import math
|
||||
|
||||
class Model:
|
||||
|
||||
def __init__(self, coords):
|
||||
def __init__(self):
|
||||
self.best_solution = []
|
||||
self.best_fitness = float("Inf")
|
||||
self.fitness_list = []
|
||||
|
||||
def init(self, coords):
|
||||
self.coords = coords
|
||||
self.N = len(coords)
|
||||
self.nodes = [i for i in range(self.N)]
|
||||
|
||||
self.best_solution = None
|
||||
self.best_fitness = float("Inf")
|
||||
self.fitness_list = []
|
||||
|
||||
def dist(self, node_0, node_1):
|
||||
"""
|
||||
Euclidean distance between two nodes.
|
||||
|
||||
@@ -3,11 +3,14 @@ import random
|
||||
from model.base_model import Model
|
||||
|
||||
class MyModel(Model):
|
||||
def __init__(self, coords):
|
||||
super().__init__(coords)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def init(self, coords):
|
||||
"""
|
||||
Put your initialization here.
|
||||
"""
|
||||
super().init(coords)
|
||||
self.log("Nothing to initialize in your model now")
|
||||
|
||||
def fit(self, max_it=1000, visualize=False):
|
||||
|
||||
Reference in New Issue
Block a user