Last active
September 5, 2018 15:44
-
-
Save sunsided/9019381 to your computer and use it in GitHub Desktop.
Binary integer programming using bintprog in Matlab
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
clear all; clc; home; | |
%{ | |
f = -[1 1.3 1.7 2]; | |
A = [1 1 1 1; % sum of all parameters | |
1 1.3 1.7 2] % weight of all parameters | |
b = [1; % sum of all parameters not larger than 1 | |
1.5]; % the target grade | |
x = bintprog(f, A, b) | |
%} | |
% your already known grades | |
have = [1 1 1.3 1]; | |
% the number of exams still to write | |
N = 9; | |
% your worst-case mean grade | |
worst_case = 1.49; | |
% the grades you expect to write | |
grades = [1 1.3 1.7 2 2.3 2.7 3]; | |
% build the objective function | |
n = repmat(grades, 1, N); | |
g = [have n]; | |
f = -g; | |
% constraints: mean grade | |
M = N + length(have); | |
A = g * (1/M); | |
b = worst_case; | |
% constraints: number of grades selected | |
Aeq = [[ones(size(have)) zeros(size(n))]; % all the known graded | |
[zeros(size(have)) ones(size(n))]]; % all but the known grades | |
beq = [length(have); | |
N]; | |
% solve the problem -- may take ages | |
x = bintprog(f, A, b, Aeq, beq); | |
% select solutions from objective function | |
grades = g(x ~= 0); | |
% remove known grades without duplicates | |
while ~isempty(have) | |
grades(find(grades == have(1), 1, 'first')) = []; | |
have(1) = []; | |
end | |
% print your worst-case scenario grades | |
there_you_go = sort(grades, 'descend') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment