### Agentmap Initialization and Setup Source: https://context7.com/noncomputable/agentmaps/llms.txt Initializes the Agentmap simulation platform, processes OSM data to generate streets and building units, and provides basic simulation lifecycle controls. ```APIDOC ## POST /agentmap/initialize ### Description Initializes the Agentmap simulation environment on a Leaflet map and populates the simulation area with streets and building units based on provided GeoJSON data. ### Method POST ### Endpoint /agentmap/initialize ### Parameters #### Request Body - **map** (Object) - Required - The Leaflet map instance. - **interval** (Number) - Required - Animation tick interval. - **bounding_box** (Array) - Required - Array of coordinates defining the simulation area. - **osm_data** (Object) - Required - GeoJSON FeatureCollection containing street and building data. ### Request Example { "map": "L.map('map')", "interval": 1, "bounding_box": [[40.714, -74.008], [40.712, -74.004]], "osm_data": { "type": "FeatureCollection", "features": [] } } ### Response #### Success Response (200) - **agentmap** (Object) - The initialized Agentmap instance. ### Simulation Controls - **agentmap.run()**: Starts the simulation. - **agentmap.pause()**: Pauses the simulation. - **agentmap.clear()**: Clears all simulation layers. ``` -------------------------------- ### Initialize Agentmap Simulation Platform Source: https://context7.com/noncomputable/agentmaps/llms.txt Initializes the Agentmap class, which transforms a Leaflet map into a simulation platform. It sets up the map, defines the simulation area using a bounding box, and configures streets and building units based on provided OSM data. The simulation can then be controlled via run, pause, and clear methods. ```javascript let map = L.map("map").setView([40.7128, -74.0060], 17); L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png").addTo(map); let agentmap = L.A.agentmap(map, 1); let bounding_box = [[40.714, -74.008], [40.712, -74.004]]; let osm_data = { "type": "FeatureCollection", "features": [ { "type": "Feature", "id": "way/123456", "geometry": { "type": "LineString", "coordinates": [[-74.007, 40.713], [-74.005, 40.713]] }, "properties": { "highway": "residential", "name": "Main Street" } } ] }; agentmap.buildingify(bounding_box, osm_data, { color: "yellow", weight: 3 }, { color: "green", front_buffer: 6, depth: 18, length: 14 } ); agentmap.run(); agentmap.pause(); agentmap.clear(); ``` -------------------------------- ### Downloading and Loading Generated Data Source: https://context7.com/noncomputable/agentmaps/llms.txt Provides methods to export generated unit and street data into JavaScript files, which can be used to avoid time-consuming regeneration in subsequent simulations. It also demonstrates how to load this pre-generated data using the `buildingify` function. ```javascript agentmap.downloadUnits(); // Creates: units_data.js containing "var units_data = {...}" agentmap.downloadStreets(); // Creates: streets_data.js containing "var streets_data = {...}" agentmap.buildingify( bounding_box, osm_data, street_options, unit_options, units_data, // Pre-generated units GeoJSON streets_data // Pre-generated streets GeoJSON ); ``` -------------------------------- ### Generate Agents with Custom or Sequential Makers Source: https://context7.com/noncomputable/agentmaps/llms.txt The agentify method creates agents on the map. It can use a custom callback function to define each agent's initial properties and placement, or utilize a built-in maker like seqUnitAgentMaker for sequential placement. Agents are CircleMarker extensions with properties for movement and behavior, and can be accessed after creation to inspect their state. ```javascript function customAgentMaker(id) { let units = agentmap.units.getLayers(); let random_unit = units[Math.floor(Math.random() * units.length)]; let unit_id = agentmap.units.getLayerId(random_unit); let center = turf.centroid(random_unit.feature); return { "type": "Feature", "geometry": { "type": "Point", "coordinates": center.geometry.coordinates }, "properties": { "layer_options": { "radius": 1.5, "color": "blue", "fillColor": "blue", "fillOpacity": 0.8 }, "place": { "type": "unit", "id": unit_id }, "health": 100, "infected": false, "home_id": unit_id } }; } agentmap.agentify(50, customAgentMaker); agentmap.agentify(10, agentmap.seqUnitAgentMaker); agentmap.agents.eachLayer(function(agent) { console.log("Agent at:", agent.getLatLng()); console.log("Agent place:", agent.place); console.log("Custom property:", agent.health); }); ``` -------------------------------- ### Schedule Agent Trips with scheduleTrip Source: https://context7.com/noncomputable/agentmaps/llms.txt The scheduleTrip method allows agents to navigate to specific units or street locations. It supports configuration for movement speed, pathfinding behavior (direct vs. street-based), and trip replacement. ```javascript let destination_unit = agentmap.units.getLayers()[5]; let destination_unit_id = agentmap.units.getLayerId(destination_unit); let goal_point = agentmap.getUnitPoint(destination_unit_id, 0.5, 0.5); let goal_place = { type: "unit", id: destination_unit_id }; agent.scheduleTrip(goal_point, goal_place, 1.5, false, false); agent.scheduleTrip(L.latLng(40.713, -74.006), { type: "unanchored" }, 2.0, true, true); let street = agentmap.streets.getLayers()[0]; let street_id = agentmap.streets.getLayerId(street); agent.scheduleTrip(street.getLatLngs()[2], { type: "street", id: street_id }, 1.0); ``` -------------------------------- ### Pathfinding and Street Graph Source: https://context7.com/noncomputable/agentmaps/llms.txt Methods for working with the street network graph and finding paths between points. ```APIDOC ## GET /agentmap/pathfinding ### Description Accesses the street network graph and provides pathfinding capabilities for agents navigating the map. ### Method GET ### Endpoint agentmap.getPathFinder(graph) ### Parameters #### Request Body - **graph** (object) - Required - The street network graph object. ### Response #### Success Response (200) - **pathfinder** (object) - Returns an initialized pathfinding instance. ### Response Example { "status": "ready", "graph_nodes": 150 } ``` -------------------------------- ### Unit and Street Access Methods Source: https://context7.com/noncomputable/agentmaps/llms.txt Methods to access specific locations within units and streets, useful for placing agents or setting destinations. ```APIDOC ## GET /agentmap/unit-access ### Description Retrieves spatial coordinates for units and street segments, including door locations and relative interior points. ### Method GET ### Endpoint agentmap.getUnitDoor(unit_id), agentmap.getStreetNearDoor(unit_id), agentmap.getUnitPoint(unit_id, x, y) ### Parameters #### Path Parameters - **unit_id** (string) - Required - The unique identifier for the unit. - **x** (float) - Optional - Relative width position (0-1). - **y** (float) - Optional - Relative depth position (0-1). ### Response #### Success Response (200) - **coordinates** (object) - Returns {lat, lng} or {x, y} coordinates for the requested point. ### Response Example { "lat": 45.523, "lng": -122.676 } ``` -------------------------------- ### Pathfinding and Street Graph Operations Source: https://context7.com/noncomputable/agentmaps/llms.txt Enables interaction with the street network graph for pathfinding. This includes accessing the graph, rebuilding it if street data changes, and retrieving intersection data for streets. It also shows how to map OpenStreetMap (OSM) IDs to internal layer IDs for accessing street data. ```javascript let graph = agentmap.streets.graph; agentmap.streets.graph = agentmap.streetsToGraph(agentmap.streets); agentmap.pathfinder = agentmap.getPathFinder(agentmap.streets.graph); let street = agentmap.streets.getLayers()[0]; console.log("Street intersections:", street.intersections); // Format: { other_street_id: [[LatLng, {street_id: index, other_street_id: index}], ...] } let leaflet_id = agentmap.streets.id_map["way/123456"]; let street_by_osm = agentmap.streets.getLayer(leaflet_id); ``` -------------------------------- ### Agent Controllers API Source: https://context7.com/noncomputable/agentmaps/llms.txt Defines custom behavior for agents using per-tick and fine controllers. ```APIDOC ## Agent Controllers - Custom Behavior ### Description Agents support two types of controller functions: a per-tick controller and a fine controller that runs before/after each movement step within a tick. ### Agentmap Controller - **agentmap.controller**: A function that runs once per tick for the entire simulation. ### Agent Controllers - **agent.controller**: A function that runs once per tick for an individual agent. - **agent.fine_controller**: A function that runs before and after each movement step within a tick for an individual agent. ### Request Example ```javascript // Set up the agentmap controller (runs once per tick for the whole simulation) agentmap.controller = function() { // Global simulation logic if (this.state.ticks % 100 === 0) { console.log("Tick:", this.state.ticks); } }; // Set up individual agent controllers agentmap.agents.eachLayer(function(agent) { // Per-tick controller for each agent agent.controller = function() { // Check if agent has arrived at destination if (this.trip.path.length === 0 && !this.trip.moving) { // Agent has finished its trip - assign new destination let random_unit = agentmap.units.getLayers()[Math.floor(Math.random() * agentmap.units.count())]; let unit_id = agentmap.units.getLayerId(random_unit); let goal = agentmap.getUnitPoint(unit_id, 0.5, 0.5); this.scheduleTrip(goal, { type: "unit", id: unit_id }, 1.2); } // Custom infection spread logic if (this.infected) { agentmap.agents.eachLayer(function(other_agent) { if (!other_agent.infected && this.getLatLng().distanceTo(other_agent.getLatLng()) < 5) { if (Math.random() < 0.1) { other_agent.infected = true; other_agent.setStyle({ color: "red", fillColor: "red" }); } } }, this); } }; // Fine controller - runs before and after each step agent.fine_controller = function() { // Fine-grained movement logic }; }); ``` ### Response Controller functions do not return values but modify agent behavior and simulation state. ``` -------------------------------- ### Agent Generation (agentify) Source: https://context7.com/noncomputable/agentmaps/llms.txt Creates and places agents within the simulation environment using custom logic or built-in generators. ```APIDOC ## POST /agentmap/agentify ### Description Generates a specified number of agents and places them on the map using a callback function to define initial state and properties. ### Method POST ### Endpoint /agentmap/agentify ### Parameters #### Request Body - **count** (Number) - Required - Number of agents to create. - **makerCallback** (Function) - Required - Function returning a GeoJSON Feature with agent properties. ### Request Example { "count": 50, "makerCallback": "function(id) { ... }" } ### Response #### Success Response (200) - **agents** (LayerGroup) - The collection of created agent markers. ### Built-in Makers - **agentmap.seqUnitAgentMaker**: Places one agent per available building unit. ``` -------------------------------- ### Define Agent Controllers for Custom Behavior Source: https://context7.com/noncomputable/agentmaps/llms.txt Agents can be controlled via per-tick functions or fine-grained controllers that execute before and after each movement step. This is useful for implementing custom logic like pathfinding, infection spread, or collision detection. ```javascript agentmap.controller = function() { if (this.state.ticks % 100 === 0) { console.log("Tick:", this.state.ticks); } }; agentmap.agents.eachLayer(function(agent) { agent.controller = function() { if (this.trip.path.length === 0 && !this.trip.moving) { let random_unit = agentmap.units.getLayers()[Math.floor(Math.random() * agentmap.units.count())]; let unit_id = agentmap.units.getLayerId(random_unit); let goal = agentmap.getUnitPoint(unit_id, 0.5, 0.5); this.scheduleTrip(goal, { type: "unit", id: unit_id }, 1.2); } }; agent.fine_controller = function() {}; }); ``` -------------------------------- ### Download Generated Data Source: https://context7.com/noncomputable/agentmaps/llms.txt Methods to export generated units and streets for reuse, avoiding regeneration time in subsequent simulations. ```APIDOC ## POST /agentmap/export ### Description Triggers a browser download for unit and street data in JavaScript format for persistence. ### Method POST ### Endpoint agentmap.downloadUnits(), agentmap.downloadStreets() ### Response #### Success Response (200) - **file** (blob) - Triggers a browser download of the data file. ``` -------------------------------- ### Accessing Unit and Street Locations Source: https://context7.com/noncomputable/agentmaps/llms.txt Provides methods to retrieve specific points within units and on streets, such as entry/exit points, points near doors, and relative positions within a unit. It also includes functions to find the nearest intersection to a street point and access unit properties like street ID and neighbors. ```javascript let door = agentmap.getUnitDoor(unit_id); console.log("Door coordinates:", door); let street_point = agentmap.getStreetNearDoor(unit_id); console.log("Street near door:", street_point); let corner = agentmap.getUnitPoint(unit_id, 0, 0); // Front-right corner let center = agentmap.getUnitPoint(unit_id, 0.5, 0.5); // Center let back_left = agentmap.getUnitPoint(unit_id, 1, 1); // Back-left corner let place = { type: "street", id: street_id }; let nearest_intersection = agentmap.getNearestIntersection(street_point, place); let unit = agentmap.units.getLayer(unit_id); console.log("Unit street ID:", unit.street_id); console.log("Unit neighbors:", unit.neighbors); // [left_neighbor, right_neighbor, across_street] console.log("Street anchors:", unit.street_anchors); ``` -------------------------------- ### Manage Agent Trip State and Velocity Source: https://context7.com/noncomputable/agentmaps/llms.txt Methods to control the lifecycle of an agent's trip, including pausing, resuming, and resetting. Additionally, provides utilities to adjust movement speed dynamically. ```javascript agent.pauseTrip(); agent.resumeTrip(); agent.resetTrip(); agent.startTrip(); agent.setSpeed(2.5); agent.multiplySpeed(1.5); agent.increaseSpeed(0.5); agent.moveIt(); ``` -------------------------------- ### Controlling Animation Interval Source: https://context7.com/noncomputable/agentmaps/llms.txt Allows control over the frequency of agent visual updates during a simulation to optimize performance. You can set the initial animation interval when creating the agentmap, change it dynamically, or disable animation updates entirely. It also provides access to the simulation's running state. ```javascript let agentmap = L.A.agentmap(map, 1); agentmap.setAnimationInterval(3); console.log("Animation interval:", agentmap.animation_interval); console.log("Running:", agentmap.state.running); console.log("Paused:", agentmap.state.paused); console.log("Ticks elapsed:", agentmap.state.ticks); ``` -------------------------------- ### Coordinate Manipulation and Geometric Operations Source: https://context7.com/noncomputable/agentmaps/llms.txt Provides methods to reverse coordinate arrays, normalize point formats into [lng, lat] arrays, validate coordinate structures, and detect intersections between coordinate paths. These utilities are essential for preparing spatial data for simulation within the AgentMaps framework. ```javascript // Reverse coordinates (convert between GeoJSON [lng,lat] and Leaflet [lat,lng]) let lngLat = [-74.006, 40.713]; let latLng = L.A.reversedCoordinates(lngLat); // [40.713, -74.006] // Works recursively for nested arrays (polygons, etc.) let polygon_coords = [[[-74.01, 40.71], [-74.00, 40.71], [-74.00, 40.72]]]; let reversed_polygon = L.A.reversedCoordinates(polygon_coords); // Convert various point formats to coordinate array [lng, lat] let from_latlng = L.A.pointToCoordinateArray(L.latLng(40.713, -74.006)); let from_feature = L.A.pointToCoordinateArray({ geometry: { type: "Point", coordinates: [-74.006, 40.713] } }); let from_array = L.A.pointToCoordinateArray([-74.006, 40.713]); // Check if an array represents valid point coordinates L.A.isPointCoordinates([40.713, -74.006]); // true L.A.isPointCoordinates([40.713]); // false // Find intersections between two coordinate arrays let street_a = [[-74.01, 40.71], [-74.00, 40.71], [-73.99, 40.71]]; let street_b = [[-74.00, 40.70], [-74.00, 40.71], [-74.00, 40.72]]; let intersections = L.A.getIntersections(street_a, street_b, ["street_a", "street_b"]); ``` -------------------------------- ### Agent Trip Control API Source: https://context7.com/noncomputable/agentmaps/llms.txt Provides methods to control agent movement, including pausing, resuming, and adjusting speed. ```APIDOC ## Agent Trip Control - Pause, Resume, Speed ### Description Methods for controlling agent movement including pausing trips, resuming, and adjusting speed dynamically. ### Methods - **agent.pauseTrip()**: Pauses the agent's current trip. - **agent.resumeTrip()**: Resumes a previously paused trip. - **agent.resetTrip()**: Resets the trip completely, clearing the path and movement state. - **agent.startTrip()**: Starts the agent traveling along the scheduled path. - **agent.setSpeed(speed)**: Sets a new constant speed for the agent (meters per tick, minimum 0.1). - **agent.multiplySpeed(factor)**: Multiplies the current speed by the given factor. - **agent.increaseSpeed(amount)**: Increases or decreases the current speed by a fixed amount. - **agent.moveIt()**: Manually triggers agent movement (usually called automatically). ### Checking Trip State - **agent.trip.moving**: Boolean indicating if the agent is currently moving. - **agent.trip.paused**: Boolean indicating if the agent's trip is paused. - **agent.trip.path.length**: Number of steps remaining in the agent's path. - **agent.trip.speed**: Current speed of the agent in meters per tick. ### Request Example ```javascript // Pause an agent's current trip agent.pauseTrip(); // Resume the paused trip agent.resumeTrip(); // Reset the trip completely agent.resetTrip(); // Start traveling along the scheduled path agent.startTrip(); // Set a new constant speed agent.setSpeed(2.5); // Multiply current speed by a factor agent.multiplySpeed(1.5); // Increase speed by 50% // Increase speed by a fixed amount agent.increaseSpeed(0.5); // Add 0.5 meters/tick // Manually trigger agent movement agent.moveIt(); // Check agent's trip state console.log("Is moving:", agent.trip.moving); console.log("Is paused:", agent.trip.paused); console.log("Path length:", agent.trip.path.length); console.log("Current speed:", agent.trip.speed); ``` ### Response These methods modify the agent's trip state and do not return values. State can be queried via `agent.trip` properties. ``` -------------------------------- ### Agent Movement API Source: https://context7.com/noncomputable/agentmaps/llms.txt Schedules an agent to travel from its current location to a destination, with options for direct movement or using streets. ```APIDOC ## scheduleTrip - Agent Movement ### Description Schedules an agent to travel from its current location to a destination, automatically navigating streets and entering/exiting units. Supports direct movement ignoring streets. ### Method `scheduleTrip` ### Parameters - **goal_point** (LatLng) - Required - The destination point. - **goal_place** (Place object) - Required - The destination unit or street. - **speed** (number) - Optional - Speed in meters per tick (default 1.0). - **move_directly** (boolean) - Optional - If true, ignores streets and moves directly to the goal_point (default false). - **replace_trip** (boolean) - Optional - If true, clears any existing trip path before scheduling the new one (default false). ### Request Example ```javascript // Schedule agent to travel to a specific unit let destination_unit_id = agentmap.units.getLayerId(agentmap.units.getLayers()[5]); let goal_point = agentmap.getUnitPoint(destination_unit_id, 0.5, 0.5); // Center of unit let goal_place = { type: "unit", id: destination_unit_id }; agent.scheduleTrip(goal_point, goal_place, 1.5, false, false); // Schedule direct movement (ignores streets) agent.scheduleTrip(L.latLng(40.713, -74.006), { type: "unanchored" }, 2.0, true, true); // Travel to a point on a street let street_id = agentmap.streets.getLayerId(agentmap.streets.getLayers()[0]); agent.scheduleTrip(agentmap.streets.getLayers()[0].getLatLngs()[2], { type: "street", id: street_id }, 1.0); ``` ### Response This method does not return a value. Trip status can be checked via `agent.trip` properties. ``` -------------------------------- ### Animation Interval Control Source: https://context7.com/noncomputable/agentmaps/llms.txt Control how frequently agents are visually redrawn during the simulation for performance optimization. ```APIDOC ## PUT /agentmap/animation ### Description Updates the animation redraw interval to balance visual smoothness against CPU performance. ### Method PUT ### Endpoint agentmap.setAnimationInterval(interval) ### Parameters #### Request Body - **interval** (integer) - Required - Redraw frequency (0 = none, 1 = every step, N = every N steps). ### Response #### Success Response (200) - **interval** (integer) - The newly set animation interval. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.