Class AgentsTasks

java.lang.Object
topics.greedy.agents.AgentsTasks

public class AgentsTasks extends Object

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 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 agent i.
    • 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 task j.
    • 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.