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 grasp_max_clique( | |
| graph: dict[int, set[int]], iterations: int = 100, alpha: float = 0.2 | |
| ) -> set[int]: | |
| """ | |
| GRASP (Greedy Randomized Adaptive Search Procedure) for maximum clique. | |
| Combines randomized greedy construction with local search. | |
| Args: | |
| graph: Dictionary representing adjacency list | |
| iterations: Number of GRASP iterations |
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 StandardCPP(CPPSolver): | |
| """ | |
| Standard Chinese Postman Algorithm for complete graphs. | |
| Time Complexity: O(n³) for matching, O(n²) for circuit | |
| Space Complexity: O(n²) | |
| This is an EXACT algorithm that always finds the optimal solution. | |
| """ |
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 TSPSolver: | |
| """Base class for TSP solvers.""" | |
| def __init__(self, problem) -> None: | |
| """ | |
| Initialize the TSP solver. | |
| Args: | |
| problem: tsplib95 problem instance | |
| """ |
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 heapq | |
| from typing import Dict, List, Tuple, Optional | |
| def dijkstra( | |
| graph, start_node: int, end_node: Optional[int] = None | |
| ) -> Tuple[Dict[int, float], Dict[int, Optional[int]]]: | |
| """ | |
| Implements Dijkstra's shortest path algorithm. |
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
| A = [ | |
| -1 -1 1; | |
| 1 3 3; | |
| -1 -1 5 | |
| ]; | |
| [QQ,RR] = qr(A); | |
| [m, n] = size(A); |
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
| x = 2; | |
| ax = abs(x); | |
| if (ax < 3.75) | |
| y = x/3.75; | |
| y = y*y; | |
| ans = 1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492 + y*(0.2659732+y*(0.360768e-1+y*0.45813e-2))))); | |
| else | |
| y=3.75/ax; |