This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import defaultdict | |
| class HopcroftKarp: | |
| def __init__(self, graph): | |
| self.graph = graph | |
| self.matching = {} | |
| self.visited = set() | |
| def bipartite_matching(self): | |
| for u in self.graph.keys(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| type HopcroftKarp struct { | |
| graph map[string][]string | |
| matching map[string]string | |
| visited map[string]bool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from scipy.optimize import linear_sum_assignment | |
| def hungarian_method(cost_matrix): | |
| row_indices, col_indices = linear_sum_assignment(cost_matrix) | |
| return list(zip(row_indices, col_indices)) | |
| # Example usage: | |
| cost_matrix = np.array([ | |
| [3, 2, 7], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "math" | |
| ) | |
| func hungarianAlgorithm(costMatrix [][]int) ([]int, int) { | |
| rows := len(costMatrix) | |
| cols := len(costMatrix[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "math" | |
| ) | |
| type Edge struct { | |
| to int | |
| cap int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def bellman_ford(graph, source): | |
| # Initialize distances and predecessors | |
| distances = {vertex: float('infinity') for vertex in graph} | |
| predecessors = {vertex: None for vertex in graph} | |
| distances[source] = 0 | |
| # Relax edges repeatedly | |
| for _ in range(len(graph) - 1): | |
| for vertex in graph: | |
| for neighbor in graph[vertex]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "math" | |
| ) | |
| func bellmanFord(graph map[string]map[string]float64, source string) (map[string]float64, map[string]string) { | |
| distances := make(map[string]float64) | |
| predecessors := make(map[string]string) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BellmanFord { | |
| // Graph represented as an adjacency list | |
| graph: Record<string, Record<string, number>>; | |
| constructor(graph: Record<string, Record<string, number>>) { | |
| this.graph = graph; | |
| } | |
| bellmanFord(source: string) { | |
| // Initialize distances and predecessors |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| #include <sys/wait.h> | |
| #include <string.h> | |
| #include <errno.h> | |
| #define BUFFER_SIZE 256 | |
| #define MAX_COMMAND_LENGTH 100 |