Example #1
0
    static void Main(string[] args)
    {
        double[]            cc       = { 1, -2 };
        double[]            cl       = { 0, 0 };
        double[]            cu       = { 10, 10 };
        double[]            rl       = { 0, 0 };
        double[]            ru       = { 2, 1 };
        int[]               astart   = { 0, 2 };
        int[]               aindex   = { 0, 1, 0, 1 };
        double[]            avalue   = { 1, 2, 1, 3 };
        HighsObjectiveSense sense    = HighsObjectiveSense.kMinimize;
        double              offset   = 0;
        HighsMatrixFormat   a_format = HighsMatrixFormat.kColwise;

        HighsModel model = new HighsModel(cc, cl, cu, rl, ru, astart, aindex, avalue, offset, a_format, sense);

        HighsLpSolver solver = new HighsLpSolver();

        HighsStatus status = solver.passLp(model);

        status = solver.run();
        HighsSolution    sol         = solver.getSolution();
        HighsBasis       bas         = solver.getBasis();
        HighsModelStatus modelStatus = solver.GetModelStatus();

        Console.WriteLine("Status: " + status);
        Console.WriteLine("Modelstatus: " + modelStatus);

        for (int i = 0; i < sol.rowvalue.Length; i++)
        {
            Console.WriteLine("Activity for row " + i + " = " + sol.rowvalue[i]);
        }
        for (int i = 0; i < sol.coldual.Length; i++)
        {
            Console.WriteLine("Reduced cost x[" + i + "] = " + sol.coldual[i]);
        }
        for (int i = 0; i < sol.rowdual.Length; i++)
        {
            Console.WriteLine("Dual value for row " + i + " = " + sol.rowdual[i]);
        }
        for (int i = 0; i < sol.colvalue.Length; i++)
        {
            Console.WriteLine("x" + i + " = " + sol.colvalue[i] + " is " + bas.colbasisstatus[i]);
        }
    }
Example #2
0
    public static HighsStatus call(HighsModel model, ref HighsSolution sol, ref HighsBasis bas, ref HighsModelStatus modelstatus)
    {
        int nc  = model.colcost.Length;
        int nr  = model.rowlower.Length;
        int nnz = model.avalue.Length;

        int[] colbasstat = new int[nc];
        int[] rowbasstat = new int[nr];

        int modelstate = 0;

        HighsStatus status = (HighsStatus)HighsLpSolver.Highs_call(nc, nr, nnz, model.colcost, model.collower, model.colupper,
                                                                   model.rowlower, model.rowupper, model.astart, model.aindex, model.avalue,
                                                                   sol.colvalue, sol.coldual, sol.rowvalue, sol.rowdual, colbasstat, rowbasstat, ref modelstate);

        modelstatus = (HighsModelStatus)modelstate;

        bas.colbasisstatus = colbasstat.Select(x => (HighsBasisStatus)x).ToArray();
        bas.rowbasisstatus = rowbasstat.Select(x => (HighsBasisStatus)x).ToArray();

        return(status);
    }