package core import "fmt" func (g *Graph) ShortestPath(source, target int) []int { if source == target { return []int{source} } res := g.SingleSourceDijkstra(source) if pr, ok := res[target]; ok { return pr.Path } return nil } func (g *Graph) FormattedRouteWithOffsets(path []int) ([]RouteStep, []int) { if len(path) == 0 { return nil, nil } var combined []int var rawOffsets []int for i := 0; i < len(path)-1; i++ { currID := path[i] nextID := path[i+1] currStation, currOk := g.Stations[currID] nextStation, nextOk := g.Stations[nextID] if currOk && currStation.IsStation { combined = append(combined, currID) rawOffsets = append(rawOffsets, i) } else if currOk && nextOk && !currStation.IsStation && !nextStation.IsStation && currStation.SolarSystemID == nextStation.SolarSystemID { combined = append(combined, currStation.SolarSystemID) rawOffsets = append(rawOffsets, i) } } lastID := path[len(path)-1] lastStation, lastOk := g.Stations[lastID] if lastOk && lastStation.IsStation { combined = append(combined, lastID) rawOffsets = append(rawOffsets, len(path)-1) } var steps []RouteStep var filteredOffsets []int for i, locID := range combined { if st, ok := g.Stations[locID]; ok { steps = append(steps, RouteStep{ ID: i, LocationID: locID, Location: fmt.Sprintf("%s - %s - %s", st.RegionName, st.SolarSystemName, st.ItemName), LocationType: "station", SystemID: st.SolarSystemID, SystemName: st.SolarSystemName, StationName: st.ItemName, Security: st.Security, RegionID: st.RegionID, Actions: make([]Action, 0), // initialize empty for JSON formatting }) filteredOffsets = append(filteredOffsets, rawOffsets[i]) } else if sys, ok := g.SolarSystems[locID]; ok { steps = append(steps, RouteStep{ ID: i, LocationID: locID, Location: fmt.Sprintf("%s - %s", sys.RegionName, sys.ItemName), LocationType: "system", SystemID: locID, SystemName: sys.ItemName, StationName: fmt.Sprintf("%s - %s", sys.RegionName, sys.ItemName), // Using Region/System name like Python code formatting does RegionID: sys.RegionID, Actions: make([]Action, 0), }) filteredOffsets = append(filteredOffsets, rawOffsets[i]) } } return steps, filteredOffsets }