Skip to content

nishanc/AI-Search-Pathway-Optimization

Repository files navigation

Search Pathway

Minimal interactive UI to run classical search algorithms (BFS, UCS, DFS, DLS, IDS, Bidirectional, Greedy, A*) on a graph.

Quick Start

python -m venv .venv
# Windows PowerShell
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
streamlit run app.py

Upload a CSV or use the bundled default_data/sample.csv. Select algorithm, start node, (optional) intermediate node, goal nodes, cost / heuristic columns if required, then Run.

PNG export available for current graph view.

Dataset Schema & Column Requirements

Your CSV must at minimum describe directed edges between nodes. Each row represents a transition (edge) from a source node (NodeID) to a neighbor (NeighborNodeID) with associated attributes. Terminal / sink nodes can have an empty NeighborNodeID (these rows are ignored for edge creation but still register the node).

Required Columns (must exist; case sensitive)

  1. NodeID (int) – Unique identifier of the source node for the edge.
  2. NodeName (string) – Human‑readable name for the node (displayed in dropdowns & hover labels).
  3. NeighborNodeID (int or blank) – Target node ID for the directed edge. Blank/NaN means no outgoing edge for that row.

Common Optional Columns (if present they become selectable)

  • TransitionCost (numeric) – Cost component (e.g., movement / resource use). Used if selected in cost columns.
  • WaitingTime (numeric) – Time delay component. Often paired with TransitionCost.
  • ResourceAvailability (categorical) – Currently only displayed if you extend UI; not used in cost/heuristic automatically.
  • SeverityLevel (categorical) – Same as above; you can map to numbers manually by adding a numeric severity column if needed.

Additional / Custom Columns

Any extra numeric columns you add (e.g., BedPressure, RiskScore, TriagePriority) will automatically appear in:

  • Cost multiselect (UCS, A*) if they are detected as numeric.
  • Heuristic selector (Greedy, A*) if numeric.

Non‑numeric columns are ignored for cost/heuristic purposes but remain attached as edge attributes.

Recommended Column Order

While the loader does not strictly enforce order, using this canonical order improves readability and avoids accidental header mistakes:

NodeID,NodeName,NeighborNodeID,TransitionCost,WaitingTime,ResourceAvailability,SeverityLevel

You may append additional columns after these. Do not rename required columns.

Data Type Expectations

Column Type Notes
NodeID int Coerced to numeric; rows with NaN NodeID are invalid
NodeName str Not coerced; keep as text
NeighborNodeID int/blank Blank => ignored for edge; still registers NodeID
TransitionCost float/int Optional; if missing and selected, treated as 0
WaitingTime float/int Optional; if missing and selected, treated as 0
(custom numeric) float/int Available for cost/heuristic selection
(categorical) str Display only unless you add numeric transforms

Edge Construction Rules

  • One row = one directed edge (NodeID -> NeighborNodeID).
  • Multiple rows with same NodeID and different NeighborNodeID produce multiple outgoing edges.
  • Duplicate edges (same source/target) will overwrite earlier attributes (last one wins).
  • Rows with missing NeighborNodeID help ensure the node itself appears in selectors.

Cost Function Logic

  • For UCS & A*: Edge cost = sum of all user‑selected cost columns.
  • If you select none, fallback = TransitionCost + WaitingTime (if present) else 0.
  • BFS/DFS/DLS/IDS/Greedy treat edges as unweighted structurally (Greedy still uses a heuristic for ordering).

Heuristic Function Logic (Greedy / A*)

  • Uses the selected numeric column as h(n).
  • If node attribute missing, heuristic = average of that column across outgoing edges; if none, 0.
  • If you select the same column for both cost and heuristic you will see a warning (allowed, but can reduce admissibility for A*).

Intermediate & Multi‑Goal Behavior

  • If an intermediate node is chosen (excluding Bidirectional), the system performs a two‑phase search:
    1. Start → Intermediate
    2. Intermediate → First reachable goal (from your selected set excluding the intermediate)
  • Combined path is shown only if both phases succeed.
  • If the intermediate is also in the goal list, Phase 2 is skipped.

Common Validation Issues

  • Typos in column headers (e.g., Node Id) will cause a hard validation error.
  • Non‑numeric values in cost or heuristic columns become NaN then treated as 0 in aggregation.
  • Empty file upload or zero goals selected stops execution with an error message.

Minimal Working Example Row

1,Node 1,4,8,2.0,High,Low

Extending the Model

To incorporate severity or resource availability into search behavior:

  1. Add a numeric column (e.g., SeverityWeight).
  2. Populate it based on your mapping (e.g., Low=1, Medium=2, High=3, Critical=5).
  3. Select it as a cost column (for UCS/A*) or as the heuristic column (Greedy/A*).

Troubleshooting

Symptom Possible Cause Action
No path returned Disconnected subgraph Verify intermediate and goals share a reachable component
All costs zero No cost columns selected & no TransitionCost/WaitingTime Select at least one numeric column
Heuristic ignored Algorithm not Greedy/A* Switch to Greedy or A*
Intermediate ignored Using Bidirectional Choose a different algorithm

About

Minimal interactive UI to run classical search algorithms (BFS, UCS, DFS, DLS, IDS, Bidirectional, Greedy, A*) on a graph.

Topics

Resources

Stars

Watchers

Forks

Languages