Linear Programming Dual

该问题要求根据输入的原始线性规划问题,输出其对偶问题。输入包含多个测试用例,每个用例包括变量数量、限制条件,以及目标函数等信息。输出是对偶问题的变量数量和限制条件,遵循线性规划对偶理论。
摘要由CSDN通过智能技术生成
Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]

Description

In this problem you have to find the dual to the linear programming problem given in general form.

Linear programming problem is set in the following way. For i = 1, 2, ... , n let xi be a variable. Some xi may be required to be non-negative or non-positive. The goal is to minimize or maximize the sum c1x1 + c2x2 + ... + cnxn under a set of restrictions.

Let A = (aij) be an m*n matrix. Denote the product ai,1x1 + ai,2x2 + ... + ai,nxn as Aix. Each restriction has the form Aix >= bi, Aix <= bi or Aix = bi.

Dual to this linear program is defined as the linear program with variables yi for i = 1, 2, ... ,m (the number of dual variables is equal to the number of restrictions in the primal problem). If the primal problem was a minimization problem, the dual is a maximization one and vice versa. The objective function of the dual problem is b1y1 + b2y2 + ... + bmym.

Each dual variable is associated with the restriction of the primal problem. If the primal problem was a maximization one, variables, associated with Aix <= bi restrictions must be non-negative and variables associated with Aix >= bi restrictions must be non-positive. In case the primal problem was a minimization one, the variables, associated with Aix >= bi restrictions must be non-negative and variables associated with Aix <= bi restrictions must be non-positive. Variables associated with Aix = bi restriction may be arbitary in either case.

The restrictions in the dual problem use matrix AT (A transposed) instead of A. Restricitions have one of the form AiT yi <= ci, AiT yi >= ci, or AiT yi= ci. You must determine the type of the restriction using the idea that the dual to the dual problem is the primal problem again.

Given primal linear programming problem, output its dual.


Input

The input contains multiple test cases. The first line of the input is a single integer T (1 <= T <= 40) which is the number of test cases. T test cases follow, each preceded by a single blank line.

The first line of each test case contains n and m (1 <= n,m <= 100).

The second line of each test contains the objective function of the given problem. The first word of the line is either "min" or "max", the objective function follows. All ci are integer, xi is given as "xi", multiplication sign is omitted, minus sign may replace the plus sign when needed to state that ci is negative. Terms with ci = 0 are omitted. If all ci are zero, "0" is given as the objective function. Terms with ci = 1 or ci = -1 are given without '1' character.

The third line contains the word "with".

Next n lines contain non-negativity and non-positivity conditions for the variables. If the variable may be arbitary, the word "arbitary" is used.

The next line contains the word "under".

Following m lines contain restrictions, all aij and bi are integers, multiplication sign is omitted, terms with aij = 0 are omitted, if for some i all aij are zero, "0" is used as the left side of the equation. Terms with aij = 1 or aij = -1 are given without '1' character.

Input file contains no extra spaces.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值