This file contains 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
# Course: https://www.edx.org/learn/computer-programming/universite-catholique-de-louvain-constraint-programming | |
# Backtracking search algorithm for solving n-queens problem | |
import time | |
from typing import Callable | |
class NQueensFilter: | |
def __init__(self, number_of_queens: int): | |
self._number_of_queens: int = number_of_queens |
This file contains 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
# Knapsack library by ortools | |
# Translated from c++ code: | |
# https://github.com/google/or-tools/blob/stable/ortools/algorithms/knapsack_solver.h | |
# https://github.com/google/or-tools/blob/stable/ortools/algorithms/knapsack_solver.cc | |
import bisect | |
import heapq | |
import math | |
from ortools.linear_solver import pywraplp |
This file contains 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 abc import ABC, abstractmethod | |
class EnemyShipBuilding(ABC): | |
@abstractmethod | |
def make_enemy_ship(self, type_of_ship: str) -> "EnemyShip": | |
pass | |
def order_the_ship(self, type_of_ship: str) -> "EnemyShip": | |
the_enemy_ship = self.make_enemy_ship(type_of_ship) |
This file contains 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 _FootballPlayer: | |
def __init__( | |
self, | |
passer_rating: int, | |
rushing_yard: int, | |
receiving_yard: int, | |
total_tackles: int, | |
interceptions: int, | |
avg_punt: int, | |
avg_kick_off_return: int, |
This file contains 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
@ECHO OFF | |
:: This batch file helps in automating tasks on cmd. | |
:: First, we sort inports using isort package. | |
:: Then, we remove unused imports using autoflake package. | |
:: Finally, we format using black package. | |
TITLE Python Files Formatter | |
ECHO /!\ Please make sure you have the following packages installed: |
This file contains 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 csv | |
import pulp #This contains LP Modeling and solver | |
import time #This is used to see how much time for solving | |
####################################################################### | |
####################################################################### | |
This file contains 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
# Example of license header: | |
# Unauthorized copying of this file, via any medium is strictly prohibited | |
# Proprietary and confidential | |
"""This file contains utility classes and functions.""" | |
import json | |
import logging | |
import openpyxl | |
This file contains 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
"""Creates a file which contains info from lp and sol file. | |
---------------- | |
Sample sol file: | |
---------------- | |
# Solution for model Mathematical Model | |
# Objective value = 140 | |
x1 10 | |
x2 20 | |
x3 30 |
This file contains 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 ortools.sat.python import cp_model | |
''' course: https://www.coursera.org/learn/solving-algorithms-discrete-optimization#about | |
About how cp works and intro to solver strategies''' | |
def patchingThe9HeavensProblem(): #sudoku problem | |
model = cp_model.CpModel() |
This file contains 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 csv | |
import pulp #This contains LP Modeling and solver | |
import time #This is used to see how much time for solving | |
import random | |
####################################################################### | |
####################################################################### | |
NewerOlder