Exemple #1
0
        last[seq] + SERVE_TIME + tm[seq, (0,)],
        0, 0, (ds[(0,), seq] + ds[seq, (0,)]) * TRANS_COST_2 + FIXED_COST_2 if
        ds[(0,), seq] + ds[seq, (0,)] <= DISTANCE_2 else M
    )
    for seq in candidate_seqs
}

route_dict = deepcopy(init_route_dict)
while True:
    route_dict, new_seq_count = merge_saving_value_pairs(
        candidate_seqs, route_dict, param , node_id_c,
        time_sorted_limit=time_sorted_limit,
        merge_seq_each_time=merge_seq_each_time
    )
    # update candidate seqs
    candidate_seqs = list(route_dict.keys())
    print("merge_seq_count: " + str(new_seq_count))
    if new_seq_count < 1:
        break

cost = 0
for k, v in route_dict.items():
    v_ = generate_seq_info(k, param)
    route_dict[k] = v_
    cost += v_.cost
    print(k)
    print(v_)

print("final cost: " + str(cost))
save_result(route_dict, data_set_num)
Exemple #2
0
        i1 = route_dict.pop(seq)
        route_dict[new_seq1] = new_info1
        i2 = route_dict.pop(neighborhood)
        route_dict[new_seq2] = new_info2
        print(seq)
        print(i1)
        print(neighborhood)
        print(i2)
        print("---")
        print(new_seq1)
        print(new_info1)
        print(new_seq2)
        print(new_info2)
        print("---")
        print("old cost: " + str(i1.cost + i2.cost))
        print("new cost: " + str(new_info1.cost + new_info2.cost))

cost = 0
for k, v in route_dict.items():
    print("-" * 30)
    print(k)
    print(v)
    new_seq, new_info = two_opt(k, v, param, best_accept=True)
    print(new_seq)
    print(new_info)
    final_route_dict[new_seq] = new_info
    cost += new_info.cost

print("-" * 20 + "\nnew cost: " + str(cost))
save_result(final_route_dict, data_set_num)