Class AgentsTasks
java.lang.Object
topics.greedy.agents.AgentsTasks
Agent-Task Assignment
Evaluates an N × N matrix of deployment costs to assign N tasks to N unique agents.
This class contrasts two structural Greedy approaches (Row-Minima vs. Column-Minima)
to demonstrate that localized voracious choices do not guarantee a globally optimal configuration.
- Author:
- vicegd
-
Constructor Summary
ConstructorsConstructorDescriptionAgentsTasks(int[][] costs) Constructs the assignment engine performing a defensive copy of the cost matrix. -
Method Summary
Modifier and TypeMethodDescriptionint[]Strategy 2: Column-Minima (Task-Driven)int[]Strategy 1: Row-Minima (Agent-Driven)intcalculateColumnStrategyCost(int[] assignments) Computes total cost incurred by Strategy 2 (Column-Minima).intcalculateRowStrategyCost(int[] assignments) Computes total cost incurred by Strategy 1 (Row-Minima).
-
Constructor Details
-
AgentsTasks
public AgentsTasks(int[][] costs) Constructs the assignment engine performing a defensive copy of the cost matrix.- Parameters:
costs- Square matrix of dimensions N x N mapping assignment costs.- Throws:
IllegalArgumentException- if the matrix is null, empty, or asymmetrical.
-
-
Method Details
-
assignTasksToAgents
public int[] assignTasksToAgents()Strategy 1: Row-Minima (Agent-Driven)
Iterates through agents (rows) sequentially, assigning each agent to their cheapest available task (column) that hasn't been claimed yet.
- Time Complexity:
O(N²) - Space Complexity:
O(N)for assignment tracking array.
- Returns:
- An array where
result[i]represents the task assigned to agenti.
- Time Complexity:
-
assignAgentsToTasks
public int[] assignAgentsToTasks()Strategy 2: Column-Minima (Task-Driven)
Iterates through tasks (columns) sequentially, assigning each task to the cheapest available agent (row) that hasn't been claimed yet.
- Time Complexity:
O(N²) - Space Complexity:
O(N)for assignment tracking array.
- Returns:
- An array where
result[j]represents the agent mapped to taskj.
- Time Complexity:
-
calculateRowStrategyCost
public int calculateRowStrategyCost(int[] assignments) Computes total cost incurred by Strategy 1 (Row-Minima).- Parameters:
assignments- Output tracking array mapping agent to task.- Returns:
- Total aggregate cost metric.
-
calculateColumnStrategyCost
public int calculateColumnStrategyCost(int[] assignments) Computes total cost incurred by Strategy 2 (Column-Minima).- Parameters:
assignments- Output tracking array mapping task to agent.- Returns:
- Total aggregate cost metric.
-