Exemplo n.º 1
0
def load_descriptor(descriptor_filename):
    data = read_json(descriptor_filename)
    if not data["appname"] == "GIFT-Surg split data":
        raise ValueError('Not a GIFT-Surg file')
    if not data["version"] == "1.0":
        raise ValueError('Cannot read this file version')
    return data
Exemplo n.º 2
0
def main(time_limit, instance_name, output_name, team_id, _):
    time_start = time.time()
    instance = read_json(instance_name + '.json')
    Interventions = instance[INTERVENTIONS_STR]
    Exclusions = instance[EXCLUSIONS_STR]
    dim = len(Interventions)
    Deltas = []
    intervention_names = list(Interventions.keys())

    for i in range(dim):
        Deltas.append(max(Interventions[intervention_names[i]]['Delta']))

    initial = [random.randint(1, int(Interventions[intervention_names[i]][TMAX_STR])) for i in range(dim)]
    time_limit = time_limit - (time.time() - time_start)

    max_teta = len(Interventions) + len(Exclusions)
    max_teta_2 = pow(len(Interventions), 2) + pow(len(Exclusions), 2)
    penalty_koef_0 = (1 + np.log(max_teta)) * max_teta
    print('penalty koeff', penalty_koef_0)
    #_, _, ini_val, initial, ini_pen = main_vns(instance, initial, (time_limit * 0.02), (1 + 70/len(Interventions)) * 300)
    _, _, ini_val, initial, ini_pen = main_vns(instance, initial, (time_limit * 0.02), penalty_koef_0)
    #_, _, ini_val, initial, ini_pen = main_vns(instance, initial,
    #                                           (time_limit * 0.02), np.log(len(Interventions)+len(Exclusions)))

    #penalty_koef = (ini_val - ini_pen/2) * 50 / max_teta
    # penalty_koef = (1 + 70/len(Interventions)) * 300
    #penalty_koef = np.log(max_teta_2/max_teta)*np.exp(max_teta_2/pow(max_teta, 2))
    penalty_koef = (ini_val - ini_pen/2) * 50 / max_teta
    print('ini_val:', ini_val, 'ini_pen:', ini_pen, 'ini_val-ini_pen:', ini_val - ini_pen, 'max_teta:', max_teta)
    print('penalty koeff', penalty_koef)
    value_cma, penalty_cma, time_cma, best_value_cma, best_penalty_cma, best_solution_cma, ini_population = \
        main_bipop(instance, ini_val, ini_pen, initial, (time_limit * 0.65), penalty_koef)
    population = []
    for i in range(len(ini_population)):
        population.append(list(ini_population[i][0]))

    time_vns, value_vns, best_value_vns, best_solution_vns, best_penalty_vns = \
        main_vns(instance, best_solution_cma, (time_limit * 0.3), penalty_koef)

    f = open(output_name, 'w')
    f.writelines(intervention_names[iteration] + ' ' + str(int(i)) + '\n' for iteration, i in
                 enumerate(best_solution_vns))
    f.close()
    print(team_id, '- Team id ')

    time_cmavns = copy.deepcopy(time_cma)
    t_last = time_cmavns[-1]
    value_cmavns = copy.deepcopy(list(value_cma))
    for i in range(len(time_vns)):
        time_cmavns.append(t_last + i + 1)
        value_cmavns.append(value_vns[i])

    plt.figure(1)
    plt.plot(time_cmavns, value_cmavns, 'b-', label='CMA-VNS')
    plt.legend()
    plt.title("Convergence of solution")
    plt.xlabel("Time")
    plt.ylabel("Objective function")
    plt.grid(True)
    plt.show()
def main_all(time_limit, instance_name, _, team_id, seed):
    time_start = time.time()
    instance = read_json(instance_name + '.json')
    Interventions = instance[INTERVENTIONS_STR]
    Exclusions = instance[EXCLUSIONS_STR]
    dim = len(Interventions)
    Deltas = []
    intervention_names = list(Interventions.keys())

    for i in range(dim):
        Deltas.append(max(Interventions[intervention_names[i]]['Delta']))

    initial = [
        random.randint(1, int(Interventions[intervention_names[i]][TMAX_STR]))
        for i in range(dim)
    ]
    time_limit = time_limit - (time.time() - time_start)

    _, _, ini_val, initial, ini_pen = main_vns(
        instance, initial, (time_limit * 0.05),
        (1 + 70 / len(Interventions)) * 300)

    max_teta = len(Interventions) + len(Exclusions)
    penalty_koef = (ini_val - ini_pen) * 50 / max_teta
    print('penalty koeff', penalty_koef)
    #value_cma, penalty_cma, time_cma, best_value_cma, best_penalty_cma, best_solution_cma, ini_population = \
    #    main_bipop(instance, initial, (time_limit * 0.25), penalty_koef)
    #population = []
    #for i in range(len(ini_population)):
    #    population.append(list(ini_population[i][0]))

    #time_vns, value_vns, best_value_vns, best_solution_vns, best_penalty_vns = \
    #    main_vns(instance, best_solution_cma, (time_limit * 0.25), penalty_koef)

    #time_pso_c, values_pso_c, value_pso_c, solution_pso_c, penalty_pso_c = \
    #    pso_main(instance, best_solution_cma, (time_limit*0.25), penalty_koef, population)

    best_state_sa, best_value_sa, best_penalty_sa, value_sa, time_sa = sa_main(
        instance, (time_limit * 0.25), penalty_koef)

    time_pso, values_pso, value_pso, solution_pso, penalty_pso = pso_main(
        instance, initial, (time_limit * 0.25), penalty_koef)
Exemplo n.º 4
0
INTERVENTIONS_STR = 'Interventions'
EXCLUSIONS_STR = 'Exclusions'
T_STR = 'T'
SCENARIO_NUMBER = 'Scenarios_number'
RESOURCE_CHARGE_STR = 'workload'
TMAX_STR = 'tmax'
DELTA_STR = 'Delta'
MAX_STR = 'max'
MIN_STR = 'min'
RISK_STR = 'risk'
START_STR = 'start'
QUANTILE_STR = "Quantile"
ALPHA_STR = "Alpha"

instance_name = 'A_09'
instance = read_json(instance_name + '.json')
Interventions = instance[INTERVENTIONS_STR]

dim = len(Interventions)
Deltas = []
Resources = instance[RESOURCES_STR]
Exclusions = instance[EXCLUSIONS_STR]
Time = instance[T_STR]

intervention_names = list(Interventions.keys())

for i in range(dim):
    Deltas.append(max(Interventions[intervention_names[i]]['Delta']))

initial = [
    random.randint(1, int(Interventions[intervention_names[i]][TMAX_STR]))
Exemplo n.º 5
0
def main():

    root = json_reader.read_json("dir_tree_1.json")
    print_folder(root)
from function_checker import main_checker
from json_reader import read_json
from function_check_constr import checker_constraints
from function_check_value import check_value
import random
import numpy as np

instance = read_json('A_10' + '.json')
TMAX_STR = 'tmax'
INTERVENTIONS_STR = 'Interventions'
EXCLUSIONS_STR = 'Exclusions'
T_STR = 'T'

Exclusions = instance[EXCLUSIONS_STR]
Time = instance[T_STR]
Interventions = instance[INTERVENTIONS_STR]
intervention_names = list(Interventions.keys())
dim = len(Interventions)

initial = [
    random.randint(1, int(Interventions[intervention_names[i]][TMAX_STR]))
    for i in range(dim)
]
value, penalty, _ = main_checker(instance, initial)
print('value1:', value, 'penalty1:', penalty)

# ---------------------------------------------------------------------#

L = [1 for _ in range(dim)]

U = [