// Numbas version: exam_results_page_options {"name": "Duality of linear programming problems (4 variables)", "extensions": ["optimisation"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variable_groups": [{"variables": ["maximise", "num_variables", "num_constraints", "objective_coefficients", "constraint_coefficients", "constraint_rhs", "inequality"], "name": "Primal problem"}, {"variables": ["dual_variables", "dual_constraints", "dual_objective_coefficients", "dual_constraint_coefficients", "dual_constraint_rhs", "dual_constraints_matrix", "dual_inequality"], "name": "Dual problem"}], "variables": {"maximise": {"templateType": "anything", "group": "Primal problem", "definition": "random(true,false)", "description": "
Is the primal problem a maximisation problem?
", "name": "maximise"}, "dual_inequality": {"templateType": "anything", "group": "Dual problem", "definition": "latex(if(maximise,'\\\\geq','\\\\leq'))", "description": "LaTeX symbol for the inequality used in the dual problem's constraints.
", "name": "dual_inequality"}, "dual_constraint_coefficients": {"templateType": "anything", "group": "Dual problem", "definition": "matrix(map(\n map(\n constraint_coefficients[y][x],\n y,\n 0..dual_variables-1\n ),\n x,\n 0..dual_constraints-1\n))", "description": "Coefficients of the constraints in the dual problem. Same format as in the primal.
", "name": "dual_constraint_coefficients"}, "constraint_coefficients": {"templateType": "anything", "group": "Primal problem", "definition": "matrix(repeat(\n random_partition(random(num_variables+1..2*num_variables+1),num_variables,0),\n num_constraints\n))", "description": "Element $(i,j)$ is the coefficient of $x_j$ in the $i$th constraint.
", "name": "constraint_coefficients"}, "dual_constraints_matrix": {"templateType": "anything", "group": "Dual problem", "definition": "matrix(\n map(\n list(dual_constraint_coefficients[j])+[dual_constraint_rhs[j]],\n j,\n 0..dual_constraints-1\n )\n)", "description": "Matrix of coefficients for the constraints in the dual problem, with another column added giving the right-hand sides of the constraints.
\nUsed to mark the student's answer for the constraints.
", "name": "dual_constraints_matrix"}, "num_constraints": {"templateType": "anything", "group": "Primal problem", "definition": "3", "description": "Number of constraints in the primal LP
", "name": "num_constraints"}, "dual_objective_coefficients": {"templateType": "anything", "group": "Dual problem", "definition": "constraint_rhs", "description": "Coefficients of each variable in the dual problem's objective function.
", "name": "dual_objective_coefficients"}, "dual_variables": {"templateType": "anything", "group": "Dual problem", "definition": "num_constraints", "description": "Number of variables in the dual problem (equal to the number of constraints in the primal)
", "name": "dual_variables"}, "dual_constraint_rhs": {"templateType": "anything", "group": "Dual problem", "definition": "objective_coefficients", "description": "Right-hand sides of the constraints in the dual problem.
", "name": "dual_constraint_rhs"}, "inequality": {"templateType": "anything", "group": "Primal problem", "definition": "latex(if(maximise,'\\\\leq','\\\\geq'))", "description": "LaTeX symbol for the inequalities in the primal problem's constraints
", "name": "inequality"}, "dual_constraints": {"templateType": "anything", "group": "Dual problem", "definition": "num_variables", "description": "Number of constraints in the dual problem (equal to the number of variables in the primal)
", "name": "dual_constraints"}, "num_variables": {"templateType": "anything", "group": "Primal problem", "definition": "4", "description": "Number of variables in the primal LP
", "name": "num_variables"}, "constraint_rhs": {"templateType": "anything", "group": "Primal problem", "definition": "repeat(random(1..20),num_constraints)", "description": "Right-hand side of each constraint
", "name": "constraint_rhs"}, "objective_coefficients": {"templateType": "anything", "group": "Primal problem", "definition": "repeat(random(1..6),num_variables)", "description": "Coefficients of each variable in the objective function.
", "name": "objective_coefficients"}}, "ungrouped_variables": [], "question_groups": [{"pickingStrategy": "all-ordered", "questions": [], "name": "", "pickQuestions": 0}], "name": "Duality of linear programming problems (4 variables)", "functions": {"describe_objective": {"type": "string", "language": "javascript", "definition": "var c = coefficients.map(function(c,i) {\n return '('+c+')*x'+(i+1);\n});\nvar expr = c.join(' + ');\nconsole.log(coefficients,c,expr);\nreturn Numbas.jme.display.exprToLaTeX(expr,'all,!noLeadingMinus',Numbas.jme.builtinScope);", "parameters": [["coefficients", "list"]]}, "describe_constraints": {"type": "number", "language": "javascript", "definition": "var num_variables=coefficients[0].length;\nvar o = '\\\\begin{align}';\nvar lines = [];\nfor(var i=0;iy1
, y2
, ...\n(Use the \"rows\" and \"columns\" boxes to change the number of constraints or variables)
\n[[0]]
\n$w = $ [[1]]
\nsubject to
\n$y_i \\geq 0$ for all $i$.
", "scripts": {}, "gaps": [{"displayType": "radiogroup", "choices": ["Maximise
", "Minimise
"], "variableReplacementStrategy": "originalfirst", "matrix": "if(maximise,[0,1],[1,0])", "variableReplacements": [], "shuffleChoices": false, "scripts": {}, "minMarks": 0, "type": "1_n_2", "maxMarks": 0, "showCorrectAnswer": true, "displayColumns": 0, "marks": 0}, {"answer": "{dual_objective_coefficients[0]}*y1+{dual_objective_coefficients[1]}*y2+{dual_objective_coefficients[2]}*y3", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "variableReplacementStrategy": "originalfirst", "expectedvariablenames": [], "showpreview": true, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "type": "jme", "showCorrectAnswer": true, "variableReplacements": [], "marks": 1, "vsetrangepoints": 5}, {"allowFractions": false, "correctAnswer": "dual_constraints_matrix", "markPerCell": false, "allowResize": true, "correctAnswerFractions": false, "variableReplacementStrategy": "originalfirst", "numRows": 1, "scripts": {"constructor": {"script": "this.display.correctAnswerLaTeX = ko.computed(function() {\n with(question.unwrappedVariables) {\n var rows = [];\n for(var i=0;i{if(maximise,'Maximise','Minimise')} $z = \\var{latex(describe_objective(objective_coefficients))}$ subject to
\n\\[ \\var{latex(describe_constraints(constraint_coefficients,constraint_rhs,inequality,'x'))} \\]
", "tags": [], "rulesets": {}, "preamble": {"css": ".matrix-input .matrix .cell:nth-child(1):not(:last-child)::after {\n content: 'y\u2081';\n}\n.matrix-input .matrix .cell:nth-child(2):not(:last-child)::after {\n content: 'y\u2082';\n}\n.matrix-input .matrix .cell:nth-child(3):not(:last-child)::after {\n content: 'y\u2083';\n}\n.matrix-input .matrix .cell:nth-child(4):not(:last-child)::after {\n content: 'y\u2084';\n}\n.matrix-input .matrix .cell:nth-child(5):not(:last-child)::after {\n content: 'y\u2085';\n}\n.matrix-input .matrix .cell:nth-child(6):not(:last-child)::after {\n content: 'y\u2086';\n}\n.matrix-input .matrix .cell:nth-child(7):not(:last-child)::after {\n content: 'y\u2087';\n}\n.matrix-input .matrix .cell:nth-child(8):not(:last-child)::after {\n content: 'y\u2088';\n}\n.matrix-input .matrix .cell:nth-child(9):not(:last-child)::after {\n content: 'y\u2089';\n}\n.matrix-input .matrix .cell:not(:last-child)::after {\n margin-left: 0.5em;\n}\n.matrix-input .matrix .cell:not(:last-child):not(:first-child)::before {\n content: '+';\n margin-right: 1em;\n}\n\n.matrix-input .matrix .cell:last-child:not(:first-child)::before {\n margin-right: 1em;\n}\n.minimisation-problem .matrix-input .matrix .cell:last-child:not(:first-child)::before {\n content: '\u2265';\n}\n.maximisation-problem .matrix-input .matrix .cell:last-child:not(:first-child)::before {\n content: '\u2264';\n}\n\n.matrix-input .matrix-wrapper .right-bracket, .matrix-input .matrix-wrapper .left-bracket {\n display: none !important;\n}", "js": "question.onHTMLAttached(function() {\n var maximise = question.unwrappedVariables.maximise;\n $(question.display.html).find('.constraint-input').addClass(maximise ? 'minimisation-problem' : 'maximisation-problem');\n});"}, "type": "question", "metadata": {"notes": "Number of variables and constraints is parameterised in the variable generation, but fixed in the question text and the answer for the dual objective function.
\nA script for the matrix entry part messes with the \"correct answer LaTeX\" property of the part display, so watch out for that if using this question with a theme other than the default.
", "licence": "Creative Commons Attribution 4.0 International", "description": "Given a linear programming problem in standard form, write down the dual problem.
"}, "variablesTest": {"condition": "", "maxRuns": 100}, "advice": "The dual problem swaps the variables and constraints in the primal problem.
\nThe primal problem is a {if(maximise,'maximisation','minimisation')} problem, so the dual problem is a {if(maximise,'minimisation','maximisation')} problem.
\nSo, the dual problem is as follows:
\n{if(maximise,'Minimise','Maximise')} $w = \\simplify{{dual_objective_coefficients[0]}y1+{dual_objective_coefficients[1]}y2+{dual_objective_coefficients[2]}y3}$ subject to
\n\\[ \\var{latex(describe_constraints(dual_constraint_coefficients,dual_constraint_rhs,dual_inequality,'y'))} \\]
", "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}]}], "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}