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
| :-use_module(library(clpfd)). | |
| warehouse(Emps_Tasks_Limit, Tasks_Demands, Conflicts, AssignedEmployees, Conflicts_Count):- | |
| length(Tasks_Demands, M), length(Emps_Tasks_Limit, N), | |
| matrix(Assignment_Matrix, M, N), | |
| % 1. Each task t is assigned to exactly Demands[t] employees | |
| maplist(demands_constraint, Assignment_Matrix, Tasks_Demands), | |
| % 2. Each employee e is assigned at most Max_Tasks[e] tasks | |
| transpose(Assignment_Matrix, AssMatTrans), | |
| maplist(employee_constraint, AssMatTrans, Emps_Tasks_Limit), |
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 java.io.IOException; | |
| import java.util.Arrays; | |
| import java.util.Scanner; | |
| // Solves the optimization problem. | |
| // Input: Number of items, Sizes, Number of packs, Capacity per pack | |
| public class Binpack { | |
| public static void main(String[] args) throws IOException { |
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
| :-use_module(library(clpfd)). | |
| binpack(Sizes, Packs_Count, Capacity, Packs):- | |
| length(Sizes, N), length(Packs, N), | |
| Packs ins 1..Packs_Count, | |
| packs_constraints(Packs, Sizes, Packs_Count, Capacity), | |
| labeling([], Packs). | |
| packs_constraints(_, _, 0, _). | |
| packs_constraints(Packs, Sizes, Pack, Capacity):- |
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 java.io.IOException; | |
| import java.util.Scanner; | |
| // Input: Investment Amount | |
| public class Car { | |
| static final int[][] prodCost = {{100, 70, 50, 35}, {200, 140, 65, 50}, {450, 300, 200, 100}}; | |
| static final int[] profit = {30, 40, 70}; |
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
| :-use_module(library(clpfd)). | |
| % Forgot to handle at least 3 cars of each type. | |
| car_production(Invest, A, B, C, Profit):- | |
| [A, B, C] ins 0..Invest, | |
| Profit #= A * 30 + B * 40 + C * 70, | |
| cost(A, (100, 70, 50, 35), CA), | |
| cost(B, (200, 140, 65, 50), CB), | |
| cost(C, (450, 300, 200, 100), CC), | |
| CA + CB + CC #=< Invest, | |
| labeling([max(Profit), ff, bisect], [A, B, C]). |
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
| :-use_module(library(clpfd)). | |
| :-use_module(library(pairs)). | |
| % System allows different exams in the same room. | |
| % Each course has only one exam. | |
| % Input | |
| % ===== | |
| % Courses = [course(Course_Name, Exam_Type)] | |
| % Resources = [room(Capacity, Type)] |
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 java.io.IOException; | |
| import java.util.Scanner; | |
| // Takes a list of weights and prints all possible position configurations that makes | |
| // the see saw balanced. | |
| // Input: L (half length of seesaw), n (number of weights), W1, W2, ... Wn | |
| public class SeeSaw { | |
| public static void main(String[] args) throws IOException { |
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
| :-use_module(library(clpfd)). | |
| % valid positions are in [-Saw_L, Saw_L]. | |
| % works for many variable weights and many variable positions. | |
| seesaw_balance(Saw_L, Weights, Positions):- | |
| length(Weights, N), length(Positions, N), NSaw_L is -Saw_L, | |
| Weights ins 0..500, Positions ins NSaw_L..Saw_L, | |
| angular_moment(Weights, Positions, 0), | |
| apart_positions(Positions), | |
| label(Positions), label(Weights). |
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
| :-use_module(library(clpfd)). | |
| patterns([ | |
| pattern(2, 0, 1, 0), | |
| pattern(1, 2, 0, 0), | |
| pattern(1, 1, 1, 1), | |
| pattern(1, 0, 3, 0), | |
| pattern(0, 3, 0, 1), | |
| pattern(0, 2, 2, 0), | |
| pattern(0, 1, 3, 1), |
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
| :-use_module(library(clpfd)). | |
| % patient(ID, Name, YearAdmitted, MonthAdmitted, | |
| % DayAdmitted, HourAdmitted, MinuteAdmitted, Status, Payment) | |
| patient(1, 'Bob Jones', 2014, 10, 1, 4, 55, 0, 2). | |
| patient(2, 'Sally Smith', 2014, 9, 29, 5, 15, 1, 0). | |
| patient(3, 'Ted Overton', 2014, 9, 30, 14, 15, 0, 0). | |
| patient(4, 'Arnold Abouja', 2014, 10, 1, 5, 0, 0, 0). | |
| patient(5, 'Seth Humbolt', 2014, 10, 1, 5, 10, 0, 0). |