⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 table.java

📁 Create a problem solver for linear programming
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package ro.simplex;import ro.utils.Fraction;/** * * @author Doan Chien Thang */public class Table {    private Dictionary dict;    private ProblemInStandardForm problem;    public Table(Dictionary dict, ProblemInStandardForm problem) {        this.dict = dict;        this.problem = problem;    }    @Override    public String toString() {        String result = "";        return result;    }    public Variable getOutVar() {        Variable resVar = null;        Variable outVar = null;        Fraction minCoef = new Fraction(0);        Objective objective = this.dict.getObjective();        if (objective.hasPositiveCoefs()) {            for (int i = 0; i < objective.getCoefs().size(); i++) {//            for (int i = objective.getCoefs().size() - 1; i >= 0; i--) {                Variable inVar = null;                if (objective.getCoefs().get(i).getOpposite().isNegative()) {                    outVar = objective.getVars().get(i);                    inVar = getInVar(outVar);                    if (inVar == null) {                        outVar = null;                        continue;                    }                    if (objective.getCoef(outVar).isGreaterThan(minCoef)) {                        resVar = outVar;                        minCoef = objective.getCoef(outVar);                    }                }            }            if (resVar == null)                this.problem.answer = Problem.IS_UNBOUND;        } else {            this.problem.answer = Problem.HAS_ONE_SOLUTION;            for (int i = 0; i < objective.getCoefs().size(); i++)                if (this.problem.baseVars.contains(objective.getVars().get(i))                && objective.getCoefs().get(i).equals(new Fraction(0))) {                    this.problem.answer = Problem.HAS_INFINITVE_SOLUTIONS;                    break;                }        }        return resVar;    }        public Variable getInVar(Variable outVar) {        Fraction f = new Fraction(0);        Variable var = null;        for (int i = 0; i < dict.getVarConstraints().size(); i++) {        //for (int i = dict.getVarConstraints().size() - 1; i >= 0; i--) {            Fraction coef = dict.getVarConstraints().get(i).getCoef(outVar);            if (coef.isNegative() && f.isGreaterThan(Fraction.divide(coef,                    dict.getVarConstraints().get(i).getValue()))) {                var = dict.getVarConstraints().get(i).getLeftVar();                f = Fraction.divide(coef,                        dict.getVarConstraints().get(i).getValue());            }        }        return var;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -