Socket
Socket
Sign inDemoInstall

graph-envs

Package Overview
Dependencies
0
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    graph-envs

A library for training and benchmarking RL agents on graphs.


Maintainers
1

Readme

GraphEnvs

Graph Reinforcement Learning (RL) Environments

Installation

First install torch and pytorch geometric. The simply use pip to install graph_envs:

  pip install graph-envs

Supported Environments

GraphEnvs-Basic:

EnvironmentDevelopedAction Space
Shortest Path$v \in \mathcal{V}$
Steiner Tree$e \in \mathcal{E}$
MST$e \in \mathcal{E}$
Minimum Vertex Cover$v \in \mathcal{V}$
TSP$v \in \mathcal{V}$
Longest Path$v \in \mathcal{V}$
Largest Clique✅ (Min Vertex Cover)$v \in \mathcal{V}$
Densest Subgraph$v \in \mathcal{V}$
Node Coloring🛠️$(v, c) \in \mathcal{V} \times \mathbb{Z} $

GraphEnvs-Extended:

EnvironmentDevelopedAction Space
MultiCast Routing$e \in \mathcal{E}$
Distribution Center Selection$v \in \mathcal{V}$
Persihable Product Delivery$v \in \mathcal{V}$
Public Transport Navigation🛠️-

Example

import gymnasium as gym 
import graph_envs
import numpy as np

env = gym.make('LongestPath-v0',
               n_nodes=10,
               n_edges=20,
               weighted=True,
               is_eval_env=True, 
               parenting=2
               )

for sd in range(0, 10):

    print(f'===== {sd} =====')
    obs, info = env.reset(seed=sd)
    mask = info['mask']
    done = False
   
    while not done:
        valid_actions = mask.nonzero()[0]
        action = np.random.choice(valid_actions)        
        obs, reward, done, _, info = env.step(action)
        print('Valid actions:', valid_actions, '  Action:', action, '  Reward:', reward, '  Done:', done)
        mask = info['mask']
        
    print(info['solution_cost'], info['solved'], info['heuristic_solution'])

Environment Details:

  1. Shortest Path: The goal is to find the shortest path from the source node to the target node. At each step, an edge is added to the path. The episode is over when we reach the target node.
  2. Steiner Tree: The goal is to find the tree with the minimum weight that connects a source node to a number of destination nodes.

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc