// Numbas version: exam_results_page_options {"name": "Denis's copy of Duality of linear programming problems (2 variables)", "extensions": ["optimisation"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"functions": {"describe_objective": {"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);", "type": "string", "parameters": [["coefficients", "list"]], "language": "javascript"}, "describe_constraints": {"definition": "var num_variables=coefficients[0].length;\nvar o = '\\\\begin{align}';\nvar lines = [];\nfor(var i=0;iThe dual problem swaps the variables and constraints in the primal problem.

\n

The primal problem is a {if(maximise,'maximisation','minimisation')} problem, so the dual problem is a {if(maximise,'minimisation','maximisation')} problem.

\n
    \n
  1. For each constraint in the primal there is a variable in the dual. So there are {dual_variables} variables in the dual.
  2. \n
  3. The right-hand side of the constraints in the primal are the coefficients of the objective function.
  4. \n
  5. The coefficients of $x_i$ in each of the primal problem's constraints form the coefficients of the $i$th constraint in the dual problem.
  6. \n
  7. The coefficients in the primal's objective function represent the right-hand sides of the constraints in the dual.
  8. \n
  9. The primal has $\\var{inequality}$ constraints and the dual has $\\var{dual_inequality}$ constraints.
  10. \n
\n

So, 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'))} \\]

", "rulesets": {}, "parts": [{"prompt": "

Write the dual of the given LP problem below. Name your variables y1, y2, ...

\n

(Use the \"rows\" and \"columns\" boxes to change the number of constraints or variables)

\n

[[0]]

\n

$w = $ [[1]]

\n

subject to

\n
[[2]] 
\n

$y_i \\geq 0$ for all $i$.

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "gaps": [{"displayColumns": 0, "matrix": "if(maximise,[0,1],[1,0])", "shuffleChoices": false, "variableReplacements": [], "choices": ["

Maximise

", "

Minimise

"], "variableReplacementStrategy": "originalfirst", "displayType": "radiogroup", "maxMarks": 0, "scripts": {}, "marks": 0, "showCorrectAnswer": true, "type": "1_n_2", "minMarks": 0}, {"vsetrangepoints": 5, "expectedvariablenames": [], "checkingaccuracy": 0.001, "type": "jme", "showpreview": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "scripts": {}, "answer": "{dual_objective_coefficients[0]}*y1+{dual_objective_coefficients[1]}*y2+{dual_objective_coefficients[2]}*y3", "marks": 1, "checkvariablenames": false, "checkingtype": "absdiff", "vsetrange": [0, 1]}, {"variableReplacementStrategy": "originalfirst", "numColumns": "2", "tolerance": 0, "allowFractions": false, "variableReplacements": [], "markPerCell": false, "numRows": 1, "showCorrectAnswer": true, "correctAnswer": "dual_constraints_matrix", "scripts": {"constructor": {"order": "after", "script": "this.display.correctAnswerLaTeX = ko.computed(function() {\n with(question.unwrappedVariables) {\n var rows = [];\n for(var i=0;iYou are given the following primal linear programming problem:

\n

{if(maximise,'Maximise','Minimise')} $z = \\var{latex(describe_objective(objective_coefficients))}$ subject to

\n

\\[ \\var{latex(describe_constraints(constraint_coefficients,constraint_rhs,inequality,'x'))} \\]

", "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"}], "variablesTest": {"maxRuns": 100, "condition": ""}, "question_groups": [{"pickingStrategy": "all-ordered", "name": "", "questions": [], "pickQuestions": 0}], "variables": {"num_variables": {"definition": "2", "templateType": "anything", "group": "Primal problem", "name": "num_variables", "description": "

Number of variables in the primal LP

"}, "dual_constraint_rhs": {"definition": "objective_coefficients", "templateType": "anything", "group": "Dual problem", "name": "dual_constraint_rhs", "description": "

Right-hand sides of the constraints in the dual problem.

"}, "dual_variables": {"definition": "num_constraints", "templateType": "anything", "group": "Dual problem", "name": "dual_variables", "description": "

Number of variables in the dual problem (equal to the number of constraints in the primal)

"}, "dual_constraints": {"definition": "num_variables", "templateType": "anything", "group": "Dual problem", "name": "dual_constraints", "description": "

Number of constraints in the dual problem (equal to the number of variables in the primal)

"}, "dual_constraint_coefficients": {"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))", "templateType": "anything", "group": "Dual problem", "name": "dual_constraint_coefficients", "description": "

Coefficients of the constraints in the dual problem. Same format as in the primal.

"}, "num_constraints": {"definition": "3", "templateType": "anything", "group": "Primal problem", "name": "num_constraints", "description": "

Number of constraints in the primal LP

"}, "constraint_rhs": {"definition": "repeat(random(1..20),num_constraints)", "templateType": "anything", "group": "Primal problem", "name": "constraint_rhs", "description": "

Right-hand side of each constraint

"}, "objective_coefficients": {"definition": "repeat(random(1..6),num_variables)", "templateType": "anything", "group": "Primal problem", "name": "objective_coefficients", "description": "

Coefficients of each variable in the objective function.

"}, "inequality": {"definition": "latex(if(maximise,'\\\\leq','\\\\geq'))", "templateType": "anything", "group": "Primal problem", "name": "inequality", "description": "

LaTeX symbol for the inequalities in the primal problem's constraints

"}, "maximise": {"definition": "random(true,false)", "templateType": "anything", "group": "Primal problem", "name": "maximise", "description": "

Is the primal problem a maximisation problem?

"}, "dual_constraints_matrix": {"definition": "matrix(\n map(\n list(dual_constraint_coefficients[j])+[dual_constraint_rhs[j]],\n j,\n 0..dual_constraints-1\n )\n)", "templateType": "anything", "group": "Dual problem", "name": "dual_constraints_matrix", "description": "

Matrix of coefficients for the constraints in the dual problem, with another column added giving the right-hand sides of the constraints.

\n

Used to mark the student's answer for the constraints.

"}, "dual_inequality": {"definition": "latex(if(maximise,'\\\\geq','\\\\leq'))", "templateType": "anything", "group": "Dual problem", "name": "dual_inequality", "description": "

LaTeX symbol for the inequality used in the dual problem's constraints.

"}, "dual_objective_coefficients": {"definition": "constraint_rhs", "templateType": "anything", "group": "Dual problem", "name": "dual_objective_coefficients", "description": "

Coefficients of each variable in the dual problem's objective function.

"}, "constraint_coefficients": {"definition": "matrix(repeat(\n random_partition(random(num_variables+1..2*num_variables+1),num_variables,0),\n num_constraints\n))", "templateType": "anything", "group": "Primal problem", "name": "constraint_coefficients", "description": "

Element $(i,j)$ is the coefficient of $x_j$ in the $i$th constraint.

"}}, "showQuestionGroupNames": false, "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.

\n

A 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.

", "description": "

Given a linear programming problem in standard form, write down the dual problem.

", "licence": "Creative Commons Attribution 4.0 International"}, "contributors": [{"name": "Denis Flynn", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1216/"}]}]}], "contributors": [{"name": "Denis Flynn", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1216/"}]}