#!/usr/bin/env node // Testet calculateRoute-Ergebnis fuer Innsbruck->Mailand und Salzburg->Innsbruck. // Laedt Engine, Seeds aus lg-roadnet.json + lg-locations.json und simuliert. const fs = require('fs'); const path = require('path'); // UMD-Engine laden const engineSrc = fs.readFileSync(path.join(__dirname, '..', 'engine.js'), 'utf-8'); const ctx = { window: {}, module: { exports: {} } }; ctx.exports = ctx.module.exports; new Function('module','exports','window','self', engineSrc)(ctx.module, ctx.exports, ctx.window, ctx.window); const L = ctx.module.exports.LogistikEngine || ctx.window.LogistikEngine || ctx.module.exports; const locations = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', '..', 'assets', 'data', 'lg-locations.json'))); const roadnet = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', '..', 'assets', 'data', 'lg-roadnet.json'))); const railnet = { nodes: [], edges: [] }; const game = L.createGame(1); game.worldState = game.worldState || {}; game.worldState.locations = locations; game.worldState.roadnet = roadnet; game.worldState.railnet = railnet; game.worldState.routesOsm = []; const TESTS = [ ['innsbruck', 'mailand'], ['mailand', 'innsbruck'], ['salzburg', 'innsbruck'], ['innsbruck', 'salzburg'], ['wien', 'innsbruck'], ]; for (const [o, t] of TESTS) { const r = L.calculateRoute(game, o, t, 'TRUCK_SMALL'); const geom = r.geometry || []; const segs = (r.segments || []).map(s => `${s.startLat.toFixed(2)},${s.startLon.toFixed(2)}→${s.endLat.toFixed(2)},${s.endLon.toFixed(2)}`).join(' · '); console.log(`${o}→${t}: provider=${r.provider} dist=${r.totalDistanceKm.toFixed(0)}km geom=${geom.length} pts, start=[${geom[0] && geom[0].map(n => n.toFixed(2)).join(',')}] end=[${geom[geom.length-1] && geom[geom.length-1].map(n => n.toFixed(2)).join(',')}]`); console.log(` Segmente: ${segs}`); }