Skip to content

Commit

Permalink
Add the assignment plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tryuan99 committed Feb 24, 2025
1 parent c323304 commit ed3a8b0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ load("@rules_pkg//pkg:tar.bzl", "pkg_tar")

package(default_visibility = ["//visibility:public"])

cc_shared_library(
name = "assignment",
deps = ["//assignment:assignment_plugin"],
)

cc_shared_library(
name = "example",
deps = ["//example:example_plugin"],
Expand All @@ -10,6 +15,7 @@ cc_shared_library(
pkg_tar(
name = "plugins",
srcs = [
":assignment",
":example",
],
extension = ".tar.gz",
Expand Down
6 changes: 6 additions & 0 deletions assignment/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ cc_test(
"@com_google_googletest//:gtest_main",
],
)

cc_library(
name = "assignment_plugin",
srcs = ["assignment_plugin.cc"],
deps = [":covered_assignment"],
)
33 changes: 33 additions & 0 deletions assignment/assignment_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// The assignment plugin includes various assignment algorithms.

#include <vector>

#include "assignment/covered_assignment.h"

extern "C" {
// Assign the agents to the tasks using a covered assignment.
int Assignment_CoveredAssignment_Assign(const int num_agents,
const int num_tasks, const float* costs,
int* assigned_agents,
int* assigned_tasks) {
// Create the cost matrix.
std::vector<std::vector<double>> cost_matrix(num_agents,
std::vector<double>(num_tasks));
for (int i = 0; i < num_agents; ++i) {
for (int j = 0; j < num_tasks; ++j) {
cost_matrix[i][j] = *(costs + num_tasks * i + j);
}
}

// Perform the assignment.
assignment::CoveredAssignment assignment(num_agents, num_tasks, cost_matrix);
const auto assignments = assignment.Assign();

// Record the assignments.
for (int i = 0; i < assignments.size(); ++i) {
assigned_agents[i] = assignments[i].first;
assigned_tasks[i] = assignments[i].second;
}
return assignments.size();
}
}

0 comments on commit ed3a8b0

Please sign in to comment.