Main Page | Report this Page
 
   
Science Forum Index  »  Math - Numerical Analysis Forum  »  simplex method
Page 1 of 1    
Author Message
Toussis Manolis
Posted: Mon Mar 12, 2007 2:35 pm
Guest
Can someone point me to a simplex implementation in c++ ?

I need a function that can solve
max(a1 x1 +a2 x2 +... + an xn)

c1 x <= B1
c2 x >= B2
c3 x == B3

xi >=0 for every i
user923005
Posted: Mon Mar 12, 2007 2:53 pm
Guest
On Mar 12, 12:35 pm, Toussis Manolis
<mano...@koppermind.homelinux.org> wrote:
Quote:
Can someone point me to a simplex implementation in c++ ?

I need a function that can solve
max(a1 x1 +a2 x2 +... + an xn)

c1 x <= B1
c2 x >= B2
c3 x == B3

xi >=0 for every i

This page:
http://web.maths.unsw.edu.au/~rsw/optlink.shtml

After one click leads to here:
http://www-unix.mcs.anl.gov/otc/Guide/faq/linear-programming-faq.html

I am sure you can solve the rest.
Peter Spellucci
Posted: Tue Mar 13, 2007 2:39 am
Guest
In article <1173728275.328041@athprx03>,
Toussis Manolis <manolis@koppermind.homelinux.org> writes:
Quote:
Can someone point me to a simplex implementation in c++ ?

I need a function that can solve
max(a1 x1 +a2 x2 +... + an xn)

c1 x <= B1
c2 x >= B2
c3 x == B3

xi >=0 for every i




http://plato.asu.edu/guide.html
for example CBC, ABACUS
hth
peter
per9000
Posted: Tue Mar 13, 2007 5:11 am
Guest
Hi Toussis,

you should try TOMNET - an optimization environment for f.x. C++/.NET
(C++/CLI and MC++), C#, Visual Basic etc.

To solve the following problem (see http://tomopt.com/docs/tomnet_quickguide/tomnet_quickguide003.php)
you could use for example the solver MINOS.

min f(x1,x2) = −7*x1−5*x2
x1+2*x2 <= 6
4*x1+x2 <= 12
x1,x2 >= 0

(Of course lower bounds and equality constraints are no problem.)

The code for solving it and printing the result on the console would
be something like this:

int main(array<System::String ^> ^args)
{

//
// Number of decision variables, linear constraints and
// nonzeros in linear constraints matrix.
//
const System::Int32 N = 2;
const System::Int32 mLin = 2;
const System::Int32 nnz = 4;

//
// Problem Name.
//
String^ Name = "lpQG";

//
// Linear objective function entries.
//
array<System::Double>^ c = gcnew array<System::Double>(N) { -7.0,
-5.0 };

//
// For use in bounds.
//
System::Double Inf = System::Double::PositiveInfinity;

//
// Lower and upper bounds for linear constraints.
//
array<System::Double>^ b_L = gcnew array<System::Double>(mLin) { -
Inf, -Inf };
array<System::Double>^ b_U = gcnew array<System::Double>(mLin)
{ 6.0, 12.0 };

//
// Lower and upper bounds for decision variables as well
// as the starting point for the solver.
//
array<System::Double>^ x_L = gcnew array<System::Double>(N) { 0.0,
0.0 };
array<System::Double>^ x_U = gcnew array<System::Double>(N) { Inf,
Inf };
array<System::Double>^ x_0 = gcnew array<System::Double>(N) { 0.0,
0.0 };

//
// Create linear constraints.
//
array<System::Double>^ Apr = gcnew array<System::Double>(nnz) { 1.0,
4.0, 2.0, 1.0 };
array<System::Int32>^ Air = gcnew array<System::Int32>(nnz) { 0, 1,
0, 1 };
array<System::Int32>^ Ajc = gcnew array<System::Int32>(N+1) { 0, 2,
4 };
TOMNET::Sparse^ A = gcnew TOMNET::Sparse(mLin, N, nnz, Air, Ajc,
Apr);

//
// Create a problem, solver and result instance.
//
TOMNET::LinearProblem^ Prob = gcnew TOMNET::LinearProblem(c, A, b_L,
b_U, x_L, x_U, x_0, Name, -Inf, nullptr, nullptr);
TOMNET::MINOS^ solver = gcnew TOMNET::MINOS();
TOMNET::Result^ result;

//
// Define a print file for solver.
//
solver->Options->PrintFile = "SnoptLP.txt";

//
// Solve the problem.
//
solver->Solve(Prob, result);

//
// Display the solution on the console.
//
Console::WriteLine(" * * * * * * * *");
Console::WriteLine(" * Solved an LP problem");
Console::WriteLine(" * Printfile: {0}", solver->Options->PrintFile);
Console::WriteLine(" * Objective: {0,10:g3}", result->f_k);
Console::WriteLine(" * Solution");
Console::WriteLine(" x_L[i] <= x_k[i] <= x_U[i]");
for (int i = 0; i < Prob->N; i++)
{
Console::WriteLine(" {0,10:g3} <= {1,10:g3} <= {2,10:g3} ",
Prob->x_L[i], result->x_k[i], Prob->x_U[i]);
}

array<System::Double>^ Ax = Prob->A->Evaluate(result->x_k);
Console::WriteLine(" * Linear constraints");
Console::WriteLine(" b_L[i] <= (A*x)[i] <= b_U[i]");
for (int i = 0; i < Prob->mLin; i++)
{
Console::WriteLine(" {0,10:g3} <= {1,10:g3} <= {2,10:g3}",
Prob->A->GetLowerBound(i), Ax[i], Prob->A->GetUpperBound(i));
}
return 0;
}

Other problem classes TOMNET deals with include global and nonlinear
problems with linear and/or nonlinear constraints. Also there are some
custom classes for numerical differentiation and sparse and dense
matrices.

You find the TOMNET Optimization Platform for .NET here http://tomopt.com/tomnet/
.. You can get a 21 day free demo through the our webpage or by
contacting me: per.stra_DELETE_ndberg@tom_DELETE_opt.co_DELETE_m


Hope that helps,
Per

--

Per Erik Strandberg
..NET Architect - Optimization
Tomlab Optimization Inc.
http://tomopt.com/tomnet/


On 12 Mar, 20:35, Toussis Manolis <mano...@koppermind.homelinux.org>
wrote:
Quote:
Can someone point me to a simplex implementation in c++ ?

I need a function that can solve
max(a1 x1 +a2 x2 +... + an xn)

c1 x <= B1
c2 x >= B2
c3 x == B3

xi >=0 for every i
per9000
Posted: Tue Mar 13, 2007 5:20 am
Guest
Hi Toussis,

you should try TOMNET - an optimization environment for f.x. C++/.NET
(C++/CLI and MC++), C#, Visual Basic .NET etc.

To solve the following problem (see http://tomopt.com/docs/tomnet_quickguide/tomnet_quickguide003.php)
you could use for example the solver MINOS.

min f(x1,x2) = -7*x1-5*x2
x1+2*x2 <= 6
4*x1+x2 <= 12
x1,x2 >= 0

(Of course lower bounds and equality constraints are no problem.)

The code for solving it and printing the result on the console would
be something like this:

int main(array<System::String ^> ^args)
{

//
// Number of decision variables, linear constraints and
// nonzeros in linear constraints matrix.
//
const System::Int32 N = 2;
const System::Int32 mLin = 2;
const System::Int32 nnz = 4;

//
// Problem Name.
//
String^ Name = "lpQG";

//
// Linear objective function entries.
//
array<System::Double>^ c = gcnew array<System::Double>(N) { -7.0,
-5.0 };

//
// For use in bounds.
//
System::Double Inf = System::Double::PositiveInfinity;

//
// Lower and upper bounds for linear constraints.
//
array<System::Double>^ b_L = gcnew array<System::Double>(mLin) { -
Inf, -Inf };
array<System::Double>^ b_U = gcnew array<System::Double>(mLin)
{ 6.0, 12.0 };

//
// Lower and upper bounds for decision variables as well
// as the starting point for the solver.
//
array<System::Double>^ x_L = gcnew array<System::Double>(N) { 0.0,
0.0 };
array<System::Double>^ x_U = gcnew array<System::Double>(N) { Inf,
Inf };
array<System::Double>^ x_0 = gcnew array<System::Double>(N) { 0.0,
0.0 };

//
// Create linear constraints.
//
array<System::Double>^ Apr = gcnew array<System::Double>(nnz) { 1.0,
4.0, 2.0, 1.0 };
array<System::Int32>^ Air = gcnew array<System::Int32>(nnz) { 0, 1,
0, 1 };
array<System::Int32>^ Ajc = gcnew array<System::Int32>(N+1) { 0, 2,
4 };
TOMNET::Sparse^ A = gcnew TOMNET::Sparse(mLin, N, nnz, Air, Ajc,
Apr);

//
// Create a problem, solver and result instance.
//
TOMNET::LinearProblem^ Prob = gcnew TOMNET::LinearProblem(c, A, b_L,
b_U, x_L, x_U, x_0, Name, -Inf, nullptr, nullptr);
TOMNET::MINOS^ solver = gcnew TOMNET::MINOS();
TOMNET::Result^ result;

//
// Define a print file for solver.
//
solver->Options->PrintFile = "SnoptLP.txt";

//
// Solve the problem.
//
solver->Solve(Prob, result);

//
// Display the solution on the console.
//
Console::WriteLine(" * * * * * * * *");
Console::WriteLine(" * Solved an LP problem");
Console::WriteLine(" * Printfile: {0}", solver->Options->PrintFile);
Console::WriteLine(" * Objective: {0,10:g3}", result->f_k);
Console::WriteLine(" * Solution");
Console::WriteLine(" x_L[i] <= x_k[i] <= x_U[i]");
for (int i = 0; i < Prob->N; i++)
{
Console::WriteLine(" {0,10:g3} <= {1,10:g3} <= {2,10:g3} ",
Prob->x_L[i], result->x_k[i], Prob->x_U[i]);
}

array<System::Double>^ Ax = Prob->A->Evaluate(result->x_k);
Console::WriteLine(" * Linear constraints");
Console::WriteLine(" b_L[i] <= (A*x)[i] <= b_U[i]");
for (int i = 0; i < Prob->mLin; i++)
{
Console::WriteLine(" {0,10:g3} <= {1,10:g3} <= {2,10:g3}",
Prob->A->GetLowerBound(i), Ax[i], Prob->A->GetUpperBound(i));
}
return 0;
}

Other problem classes TOMNET deals with include global and nonlinear
problems with linear and/or nonlinear constraints. Also there are some
custom classes for numerical differentiation and sparse and dense
matrices.

You find the TOMNET Optimization Platform for .NET here http://tomopt.com/tomnet/
.. You can get a 21 day free demo through the our webpage or by
contacting me: per.stra_DELETE_ndberg@tom_DELETE_opt.co_DELETE_m


Hope that helps,
Per

--

Per Erik Strandberg
..NET Architect - Optimization
Tomlab Optimization Inc.
http://tomopt.com/tomnet/


On 12 Mar, 20:35, Toussis Manolis <mano...@koppermind.homelinux.org>
wrote:
Quote:
Can someone point me to a simplex implementation in c++ ?

I need a function that can solve
max(a1 x1 +a2 x2 +... + an xn)

c1 x <= B1
c2 x >= B2
c3 x == B3

xi >=0 for every i
per9000
Posted: Tue Mar 13, 2007 5:39 am
Guest
Sorry for the double post - my reader was slow.

Per

--

Per Erik Strandberg
..NET Architect - Optimization
Tomlab Optimization Inc.
http://tomopt.com/tomnet/

On 12 Mar, 20:35, Toussis Manolis <mano...@koppermind.homelinux.org>
wrote:
Quote:
Can someone point me to a simplex implementation in c++ ?

I need a function that can solve
max(a1 x1 +a2 x2 +... + an xn)

c1 x <= B1
c2 x >= B2
c3 x == B3

xi >=0 for every i
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Tue Oct 14, 2008 6:48 am