Giter VIP home page Giter VIP logo

Comments (4)

ingambe avatar ingambe commented on June 15, 2024

Hi Keng,

Thanks a lot for the compliments :)

There may be multiple ways to do it. The simplest approach IMO would be to use the callback to store the best solution found.

In CustomCallbacks:


class CustomCallbacks(DefaultCallbacks):
    
    def __init__(self, legacy_callbacks_dict: Dict[str, callable] = None):
        super(CustomCallbacks, self).__init__(legacy_callbacks_dict)
        self.best_solution_makespan = float('inf')
        self.best_solution = None

    def on_episode_end(self, worker: "RolloutWorker", base_env: BaseEnv,
                       policies: Dict[PolicyID, Policy],
                       episode: MultiAgentEpisode, **kwargs):
        env = base_env.get_unwrapped()[0]
        if env.last_time_step != float('inf'):
            episode.custom_metrics['make_span'] = env.last_time_step
            if env.last_time_step < self.best_solution_makespan:
                self.best_solution_makespan = env.last_time_step
                self.best_solution = env.solution


In main, get the best solution back:


print(f'best solution makespan {config['callbacks'].best_solution_makespan}')
print(f'best solution {config['callbacks'].best_solution}')

Tell me if it solves the issue :)

from rl-job-shop-scheduling.

kenghweeng avatar kenghweeng commented on June 15, 2024

Assuming I've made the correct modifications in the CustomCallbacks class, I've modified the while loop of the original main to be:

trainer = PPOTrainer(config=config)
while start_time + stop['time_total_s'] > time.time():
        result = trainer.train()

        result = wandb_tune._clean_log(result)
        log, config_update = _handle_result(result)
        wandb.log(log)
        # wandb.config.update(config_update, allow_val_change=True)

ray.shutdown()
print(f'best solution makespan {config['callbacks'].best_solution_makespan}')
print(f'best solution {config['callbacks'].best_solution}')

It will throw: AttributeError: type object 'CustomCallbacks' has no attribute 'best_solution_makespan'

from rl-job-shop-scheduling.

ingambe avatar ingambe commented on June 15, 2024

I've doubled check and effectively, even when I put the variables as static for the CustomCallbacks, it seems to be overwritten

It was a bit tricky but I finally managed to store the solution, I had to modify the environment to store the best solution as the on_episode_end method of RLLib is not really called at the end of the episode and because of that the solution was not saved properly

The code is available in its own branch: https://github.com/prosysscience/RL-Job-Shop-Scheduling/tree/save_solution
Please give it a try and tell me if it works :)

from rl-job-shop-scheduling.

kenghweeng avatar kenghweeng commented on June 15, 2024

Okay, I'll let you know! I'd probably write a helper to generate the Gantt chart based on the solution generated, and create a PR :)

from rl-job-shop-scheduling.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.