Exemplo n.º 1
0
from lib.egate_model import Model
from arguments import args
import argparse

if __name__ == "__main__":
    args = args()

    device = torch.device(args.device)

    N_JOBS = args.N_JOBS
    CAP = args.CAP
    MAX_COORD = args.MAX_COORD
    MAX_DIST = args.MAX_DIST
    n_steps=args.N_STEPS

    model = Model(4,64,2,16)
    model = model.to(device)
    envs = create_batch_env()
    model.load_state_dict(torch.load('model/v5-500.model'))

    states = envs.reset()
    print ("before mean cost:",np.mean([env.cost for env in envs.envs]))
    _,states,history = roll_out(model,envs,states,n_steps)
    print ("after mean cost:",np.mean([env.cost for env in envs.envs]))

    history = np.array(history)

    a = [env.env.tours() for env in envs.envs]
    for i in range(len(a)):
        print(i)
        print(a[i])
Exemplo n.º 2
0
import math
import vrp_env
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.data import Data, DataLoader
from lib.utils_train import create_batch_env, train
from lib.egate_model import Model
from arguments import args
import argparse

if __name__ == "__main__":
    args = args()

    device = torch.device(args.device)

    N_JOBS = int(args.N_JOBS)
    CAP = int(args.CAP)
    batch_size = int(args.BATCH)
    MAX_COORD = int(args.MAX_COORD)
    MAX_DIST = float(args.MAX_DIST)
    LR = float(args.LR)

    envs = create_batch_env(128, 99)

    model = Model(4, 64, 2, 16)
    model = model.to(device)

    train(model, envs, 1000, 10, 10, 4)
    torch.save(model.state_dict(), "model/v5-latest.model")
Exemplo n.º 3
0
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.data import Data,DataLoader
from lib.utils_train import create_batch_env, train
from lib.egate_model import Model
from arguments import args
import argparse

if __name__ == "__main__":
    args = args()

    device = torch.device(args.device)

    N_JOBS = args.N_JOBS
    CAP = args.CAP
    MAX_COORD = args.MAX_COORD
    MAX_DIST = args.MAX_DIST
    LR = args.LR
    DEPOT_END = args.DEPOT_END
    SERVICE_TIME = args.SERVICE_TIME
    TW_WIDTH = args.TW_WIDTH

    envs = create_batch_env(128,99)

    model = Model(8,64,2,16)
    model = model.to(device)

    # model.load_state_dict(torch.load("model/v8-tw-iter200-rm25-latest.model"))
    train(model,envs,1000,20,10,4,n_remove=10)
    torch.save(model.state_dict(), "model/v8-tw-iter200-rm25-latest.model")
Exemplo n.º 4
0
    device = torch.device(args.device)

    N_JOBS = args.N_JOBS
    CAP = args.CAP
    MAX_COORD = args.MAX_COORD
    MAX_DIST = args.MAX_DIST
    LR = args.LR
    DEPOT_END = args.DEPOT_END
    SERVICE_TIME = args.SERVICE_TIME
    TW_WIDTH = args.TW_WIDTH

    N_ROLLOUT = args.N_ROLLOUT
    ROLLOUT_STEPS = args.ROLLOUT_STEPS
    N_STEPS = args.N_STEPS

    model = Model(8, 64, 2, 16)
    model = model.to(device)
    model.load_state_dict(torch.load("model/v8-tw-iter200-rm25-latest.model"))

    inputs = read_input("data/vrptw_99.npy", N_STEPS)

    def eval(batch_size=128, n_steps=100, instance=None):
        envs = create_batch_env(batch_size, 99, instance=instance)
        states = envs.reset()
        states, history, actions, values = roll_out(model, envs, states,
                                                    n_steps, False, 64)
        best_index = np.argmin([env.best for env in envs.envs])
        best_cost = envs.envs[best_index].best
        best_tours = envs.envs[best_index].best_sol
        print("best cost:", best_cost)
        print("best tours:", best_tours)