{"record":{"id":"282f39714707ffe4","repo":"a-b-street/abstreet","slug":"todo-handle-working-and-living-in-the-same-building","errorCode":null,"errorMessage":"TODO: handle working and living in the same building","messagePattern":"TODO: handle working and living in the same building","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"synthpop/src/make/activity_model.rs","lineNumber":212,"sourceCode":"            prettyprint_usize(num_trips_passthru),\n            prettyprint_usize(num_trips - s.people.len()),\n            prettyprint_usize(residents.len()),\n            prettyprint_usize(workers.len()),\n        );\n        s\n    }\n}\n\nfn create_prole(\n    home: TripEndpoint,\n    work: TripEndpoint,\n    map: &Map,\n    rng: &mut XorShiftRng,\n) -> Result<PersonSpec> {\n    if home == work {\n        // TODO: handle edge-case of working and living in the same building...  maybe more likely\n        // to go for a walk later in the day or something\n        bail!(\"TODO: handle working and living in the same building\");\n    }\n\n    let mode = match (&home, &work) {\n        // commuting entirely within map\n        (TripEndpoint::Building(home_bldg), TripEndpoint::Building(work_bldg)) => {\n            // Decide mode based on walking distance. If the buildings aren't connected,\n            // probably a bug in importing; just skip this person.\n            let dist = if let Some(path) = PathRequest::between_buildings(\n                map,\n                *home_bldg,\n                *work_bldg,\n                PathConstraints::Pedestrian,\n            )\n            .and_then(|req| map.pathfind(req).ok())\n            {\n                path.total_length()\n            } else {\n                bail!(\"no path found\");","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/synthpop/src/make/activity_model.rs#L194-L230","documentation":"create_prole (used by proletariat_robot) builds a synthetic person from a home and work endpoint, but the case where a person's home and work are the same building is not yet implemented, so it deliberately fails with a TODO error. The code even suggests such a person would likely just stay near home.","triggerScenarios":"Generating a synthetic population where a sampled job and residence resolve to the identical building, e.g. dense mixed-use OSM areas or a small map where everyone works where they live.","commonSituations":"Small test maps with few buildings, OSM imports where shops with residences produce home==work matches, population generators that sample home and work independently without exclusion.","solutions":["Resample the work (or home) building when it equals the home building","Skip or merge such individuals during population generation before calling create_prole","Implement the TODO: treat the person as staying home / no commute trip"],"exampleFix":"// before\nlet person = create_prole(map, rng, home, work, ...)?;\n// after\nlet work = if work == home { sample_other_building(map, rng, &home) } else { work };\nlet person = create_prole(map, rng, home, work, ...)?;","handlingStrategy":"validation","validationCode":"if home == work {\n    work = sample_distinct_building(map, rng, &home);\n}","typeGuard":null,"tryCatchPattern":"match create_prole(map, rng, home, work, ...) {\n    Ok(p) => Some(p),\n    Err(e) if e.to_string().contains(\"same building\") => None, // skip\n    Err(e) => return Err(e),\n}","preventionTips":["Sample home and work from disjoint building sets","Resample or skip individuals whose workplace equals their residence","Handle the same-building case in your generator before calling create_prole"],"tags":["synthpop","population-generation","unimplemented"],"backgroundTag":"unsupported-operation","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}