⑤可動ノードとは? 物流ゲーミフィケーション
④で出てきた「可動ノード」とは?これは気になる。
問題の本質はここなんだよな。突っ込んでみる。
要は、「グラフ深層学習」に出てきたダイナミックグラフの事か。
ChatGPT 4oが上限なので、Claudeに話を振る。
ゼロから始めるのか、大変だな…
いきなり、こういうのを返してくるから、Claude先生は凄いんだよなぁ…
結論出ちゃうから、むしろ最初からは使わない様にしているくらい。
こういうのを、インタラクティブに作りたいんだよなぁ。
(各階が地図になってるやつ)
今見てると、同じノードが時系列で繋がれているのは良いんだけど、これは実線じゃない方が良いんだよな、細かい話。後で実装する時に直そう。
うん、これはPyGameだな。
マーメイド形式では、こう。
graph TD
subgraph T8[Time: 8:00]
A8[Location A]
B8[Location B]
C8[Location C]
end
subgraph T9[Time: 9:00]
A9[Location A]
B9[Location B]
C9[Location C]
end
subgraph T10[Time: 10:00]
A10[Location A]
B10[Location B]
C10[Location C]
end
%% 1時間の移動
A8 --> B9
B8 --> C9
A9 --> B10
B9 --> C10
%% 2時間の移動
A8 -.-> C10
%% 待機
A8 --> A9
B8 --> B9
C8 --> C9
A9 --> A10
B9 --> B10
C9 --> C10
なるほど…
そして2DではPyGameだし、3DではPanda3Dか…
そして、すぐにClaudeはトークン上限に達してしまう(笑)
最後に、Geminiに訊くか。
すげーな、ごっついコード書いてくるな…(ひいちゃう位)
import pygame
import random
# Pygameの初期化
pygame.init()
# 画面サイズ
WIDTH = 800
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("N対N配車ゲーム")
# 色
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Locationクラス
class Location:
def __init__(self, x, y, name):
self.x = x
self.y = y
self.name = name
self.radius = 20
self.passengers = []
def draw(self):
pygame.draw.circle(screen, WHITE, (self.x, self.y), self.radius)
font = pygame.font.Font(None, 20)
text = font.render(self.name, True, BLACK)
text_rect = text.get_rect(center=(self.x, self.y))
screen.blit(text, text_rect)
# 乗客の表示
for i, passenger in enumerate(self.passengers):
pygame.draw.rect(screen, BLUE, (self.x + self.radius, self.y - self.radius + (i*20),10,10))
def add_passenger(self, destination):
self.passengers.append(Passenger(self, destination))
# Passengerクラス
class Passenger:
def __init__(self, start, destination):
self.start = start
self.destination = destination
# Vehicleクラス
class Vehicle:
def __init__(self, x, y, max_passenger=2):
self.x = x
self.y = y
self.width = 15
self.height = 25
self.speed = 5
self.is_moving = False
self.destination = None
self.passengers = []
self.max_passenger = max_passenger
def draw(self):
pygame.draw.rect(screen, RED, (self.x, self.y, self.width, self.height))
# 乗客表示
for i, passenger in enumerate(self.passengers):
pygame.draw.rect(screen, GREEN, (self.x + self.width, self.y + (i*10), 5,5))
def move(self, dest_x, dest_y):
# 移動先の設定
dx = dest_x - self.x
dy = dest_y - self.y
distance = (dx ** 2 + dy ** 2) ** 0.5
# 移動の処理
if distance > 0:
move_x = dx / distance * self.speed
move_y = dy / distance * self.speed
self.x += move_x
self.y += move_y
if distance < self.speed:
self.x = dest_x
self.y = dest_y
self.is_moving = False
def assign_destination(self, location):
self.destination = location
self.is_moving = True
def add_passenger(self, passenger):
if len(self.passengers) < self.max_passenger:
self.passengers.append(passenger)
return True
else:
return False
def remove_passenger(self, passenger):
self.passengers.remove(passenger)
# Locationの作成
locations = {}
locations["A8"] = Location(100, 100, "A")
locations["B8"] = Location(300, 100, "B")
locations["C8"] = Location(500, 100, "C")
locations["A9"] = Location(100, 300, "A")
locations["B9"] = Location(300, 300, "B")
locations["C9"] = Location(500, 300, "C")
locations["A10"] = Location(100, 500, "A")
locations["B10"] = Location(300, 500, "B")
locations["C10"] = Location(500, 500, "C")
# 移動ルート
routes = {
("A8", "B9"),
("B8", "C9"),
("A9", "B10"),
("B9", "C10"),
("A8","C10")
}
wait_routes = {
("A8","A9"),
("B8", "B9"),
("C8","C9"),
("A9", "A10"),
("B9", "B10"),
("C9", "C10"),
}
# 時間管理
time = 8 #初期時間
time_interval = 60
current_location_names = [f"{c}{time}" for c in ["A","B","C"]]
next_location_names = [f"{c}{time + 1}" for c in ["A","B","C"]]
tick_time = 0
#Vehicleの作成
vehicle = Vehicle(50, 100)
# ゲームループ
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_x, mouse_y = event.pos
# Locationのクリック判定
for key, location in locations.items():
if location.x - location.radius < mouse_x < location.x + location.radius and \
location.y - location.radius < mouse_y < location.y + location.radius:
# 車両が移動中でなければ、移動先を設定
if vehicle.is_moving == False and any(loc == key for loc in current_location_names):
vehicle.assign_destination(location)
# 乗客の乗車処理
if location.passengers:
for passenger in location.passengers:
if vehicle.add_passenger(passenger):
location.passengers.remove(passenger)
break
# 描画
screen.fill(BLACK)
# Locationの描画
for key, location in locations.items():
location.draw()
# ルートの描画
for start_key, end_key in routes:
start_loc = locations.get(start_key)
end_loc = locations.get(end_key)
if start_loc and end_loc:
pygame.draw.line(screen, WHITE, (start_loc.x, start_loc.y), (end_loc.x, end_loc.y))
# 待機ルートの描画
for start_key, end_key in wait_routes:
start_loc = locations.get(start_key)
end_loc = locations.get(end_key)
if start_loc and end_loc:
pygame.draw.line(screen, WHITE, (start_loc.x, start_loc.y), (end_loc.x, end_loc.y), 2)
#車両の描画
vehicle.draw()
# 車両の移動
if vehicle.is_moving and vehicle.destination:
vehicle.move(vehicle.destination.x, vehicle.destination.y)
# 到着時処理
if vehicle.x == vehicle.destination.x and vehicle.y == vehicle.destination.y:
# 乗客の降車
if vehicle.passengers:
for passenger in vehicle.passengers:
if passenger.destination.name == vehicle.destination.name:
vehicle.remove_passenger(passenger)
# 時間経過処理
tick_time += 1
if tick_time % time_interval == 0:
time += 1
tick_time = 0
current_location_names = next_location_names
next_location_names = [f"{c}{time + 1}" for c in ["A","B","C"]]
for location_name in current_location_names:
current_location = locations.get(location_name)
# ランダムな乗客追加
if current_location:
destination_list = [loc for loc in locations.values() if loc != current_location]
if destination_list:
destination = random.choice(destination_list)
current_location.add_passenger(destination)
# 時間表示
font = pygame.font.Font(None, 36)
text = font.render(f"Time: {time}:00", True, WHITE)
screen.blit(text, (10, 10))
pygame.display.flip()
# Pygameの終了
pygame.quit()
すると倉庫の在庫問題、製造スケジューリング、N対N配車は全て同じモデルで表現できる事になる。