예제 #1
0
        public static void Main()
        {
            LpSolve.Init();

            SolveA();
            SolveB();
        }
예제 #2
0
        public static void Main()
        {
            LpSolve.Init();

            //Test();
            FormulateSample.Main2();
        }
예제 #3
0
        public LpSolveMilpSolver(int integerWidth, double epsilon = 0.000000001) : base(integerWidth, epsilon)
        {
            var dllFolderPath = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), Environment.Is64BitProcess ? @"NativeBinaries\win64\" : @"NativeBinaries\win32\");

            LpSolve.Init(dllFolderPath);
            LpSolvePointer = LpSolve.make_lp(0, 0);
        }
예제 #4
0
        protected override void InternalLoadModelFromFile(string modelPath)
        {
            LpSolvePointer.delete_lp();
            LpSolve.Init();
            var IMPORTANT = 3;
            var MPS_FREE  = 8;

            LpSolvePointer = Path.GetExtension(modelPath)?.Trim('.').ToLower() == "lp" ? LpSolve.read_LP(modelPath, IMPORTANT, null) : LpSolve.read_MPS(modelPath, IMPORTANT | MPS_FREE);
        }
예제 #5
0
        public static void Main()
        {
            Debug.WriteLine(Environment.CurrentDirectory);

            LpSolve.Init();

            Test();

            //TestMultiThreads();
        }
예제 #6
0
        public static void Main()
        {
            LpSolve.Init();

            Demo();
        }
예제 #7
0
        public static ISet <Donor> FindOptimalDonors(ISet <Donor> donors, CofinanceInfo bounds)
        {
            var result = new HashSet <Donor>();

            if (donors.Count == 0)
            {
                return(result);
            }

            LpSolve.Init();

            using (var lp = LpSolve.make_lp(0, donors.Count))
            {
                lp.set_verbose(3);
                var boundRow   = new double[donors.Count];
                var boundColno = new int[donors.Count];

                var targetRow   = new double[donors.Count];
                var targetColno = new int[donors.Count];

                var i = 0;
                foreach (var donor in donors)
                {
                    lp.set_col_name(i + 1, donor.Channel.Id.ToString());
                    lp.set_binary(i + 1, true);
                    boundColno[i] = targetColno[i] = i + 1;
                    boundRow[i]   = bounds.ChannelsPrices[donor.Channel];
                    targetRow[i]  = donor.Effect;
                    i++;
                }

                lp.set_add_rowmode(true);
                lp.add_constraintex(donors.Count, boundRow, boundColno, lpsolve_constr_types.LE, bounds.R);
                lp.set_add_rowmode(false);

                lp.set_obj_fnex(donors.Count, targetRow, targetColno);
                lp.set_maxim();

                var lpResult = lp.solve();

                if (lpResult != lpsolve_return.OPTIMAL)
                {
                    throw new Exception($"Optimization failed! LP result code: {lpResult}");
                }

                var variableValues = new double[donors.Count];
                lp.get_variables(variableValues);

                i = 0;
                foreach (var donor in donors)
                {
                    if (Math.Abs(variableValues[i] - 1) < 1e-10)
                    {
                        result.Add(donor);
                    }

                    i++;
                }
            }

            return(result);
        }
예제 #8
0
        public static void Main()
        {
            LpSolve.Init();

            zadanie8();
        }
예제 #9
0
 public MixedStrategy(int[,] matrix)
 {
     _matrix = matrix;
     LpSolve.Init();
 }