Exemple #1
0
   /* bool LPSolver::Simplex(int phase) {
        int x = phase == 1 ? m+1 : m;
        while (true) {
            int s = -1;
            for (int j = 0; j <= n; j++) {
                if (phase == 2 && N[j] == -1) continue;
                if (s == -1 || D[x][j] < D[x][s] || D[x][j] == D[x][s] && N[j] < N[s]) s = j;
            }
            if (D[x][s] >= -EPS) return true; // fertig
            int r = -1;
            for (int i = 0; i < m; i++) {
                if (D[i][s] <= 0) continue;
                if (r == -1 || D[i][n+1] / D[i][s] < D[r][n+1] / D[r][s] ||
                    D[i][n+1] / D[i][s] == D[r][n+1] / D[r][s] && B[i] < B[r]) r = i;
            }
            if (r == -1) return false; // alle eintraege in der spalte negativ -> unbeschraenkt!
            Pivot(r, s);
        }
    }*/
double LPSolver::Solve(RealVector &x)
{
    int r = 0;
    for (int i = 1; i < m; i++) if (D(i,n+1) < D(r,n+1)) r = i;
    // D[r][n+1] smalles element
    
    // if < 0
    
    // phase 1
    if (D(r,n+1) <= -eps) {
        Pivot(r, n);
        if (!Simplex(1) || D(m+1,n+1) < -eps) return -std::numeric_limits<double>::infinity();  // infeasible!
        for (int i = 0; i < m; i++)
            if (B[i] == -1)
            {
                int s = -1;
                for (int j = 0; j <= n; j++)
                    if (s == -1 || D(i,j) < D(i,s) || D(i,j) == D(i,s) && N[j] < N[s]) s = j;
                Pivot(i, s);
            }
    }
    // otherwise phase 2...
    if (!Simplex(2)) return std::numeric_limits<double>::infinity();    // unbounded
    x = RealVector(n);
    for (int i = 0; i < m; i++) if (B[i] < n) x(B[i]) = D(i,n+1);
    return D(m,n+1);
}
Exemple #2
0
void LRWWSimplex::doSetup_(const Function &objFunc,
                           const vector< double > &x0,
                           const Solver::Setup &solverSetup,
                           const Constraints &C)
{
  const int n = objFunc.getN();
  double fx;
  double fxi;
  int i;
  vector< double > xi(n);
  double stepSize = 1.0;  // TODO: read this from solverSetup
  
  NativeSolver::doSetup_(objFunc, x0, solverSetup, C);
  
  state_.S = Simplex(n);
  
  fx = objFunc(x0);
  state_.S.setVertex(0, x0, fx);
  for(i = 1; i < n + 1; i++)
  {
    xi = x0;
    xi[i - 1] += stepSize;
    fxi = objFunc(xi);
    state_.S.setVertex(i, xi, fxi);
  }
  
  state_.S.sortVertices();
  
  xe_.resize(n);
  xic_.resize(n);
  xoc_.resize(n);
  xr_.resize(n);
}
//#####################################################################
// Function Add_Element_If_Not_Already_There
//#####################################################################
// will ONLY incrementally update incident_elements, assumes number_nodes is already set to accommodate the new element
template<int d> int SIMPLEX_MESH<d>::
Add_Element_If_Not_Already_There(const VECTOR<int,d+1>& nodes)
{
    if(int element=Simplex(nodes)) return element;
    elements.Append(nodes);
    for(int i=1;i<=d+1;i++) (*incident_elements)(nodes[i]).Append(elements.m);
    return elements.m;
}
Exemple #4
0
int main() {
  //n = 1;m=1;
  //V= 0.0;
  //c[1] = 1.0;
  //A[1][1] = 1.0;
  //b[1] = 5.0;
  //Simplex();
  //printf("V = %.3f\n",V);

  while(scanf("%d",&v1[1]) == 1) {
    for(int i = 2; i<=6; i++)
      scanf("%d",&v1[i]);
    n = 4;
    m = 6;
    for(int i = 0 ; i<=m+1; i++)
      for(int j=0; j<=n+m+2; j++)
        A[i][j] = c[j] = 0;
    memset(b,0,sizeof(b));
    V = 0.0;
    /*
    n 为未知数个数
    m 为约束个数
    目标:siama(c[i]*xi)
    约束:sigma(A[i][j]*xj) <=b[i]; j = 1 ... n
    解存在X里面
    */
    b[1] = v1[1] ;
    A[1][1] = 1;
    A[1][4] = 1;
    b[2] = v1[2] ;
    A[2][1] = 1;
    A[2][3] = 1;
    b[3] = v1[3] ;
    A[3][3] = 1;
    A[3][4] = 1;
    b[4] = v1[4] ;
    A[4][2] = 1;
    A[4][3] = 1;
    b[5] = v1[5] ;
    A[5][2] = 1;
    A[5][4] = 1;
    b[6] = v1[6] ;
    A[6][1] = 1;
    A[6][2] = 1;
    c[1] = 1;
    c[2] = 1;
    c[3] = 1;
    c[4] = 1;
    Simplex();
    //printf("V = %.3f\n",V);
    printf("%.3f %.3f %.3f %.3f\n",X[1],X[2],X[3],X[4]);

  }
  return 0;
}
 DOUBLE Solve(VD &x) {
  int r = 0;
  for (int i = 1; i < m; i++) if (D[i][n + 1] < D[r][n + 1])
    r = i;
  if (D[r][n + 1] < -EPS) {
   Pivot(r, n);
   if (!Simplex(1) || D[m + 1][n + 1] < -EPS)
     return -numeric_limits<DOUBLE>::infinity();
   for (int i = 0; i < m; i++) if (B[i] == -1) {
    int s = -1;
    for (int j = 0; j <= n; j++)
     if (s == -1 || D[i][j] < D[i][s] ||
         D[i][j] == D[i][s] && N[j] < N[s])
       s = j;
    Pivot(i, s); } }
  if (!Simplex(2)) return numeric_limits<DOUBLE>::infinity();
  x = VD(n);
  for (int i = 0; i < m; i++) if (B[i] < n)
    x[B[i]] = D[i][n + 1];
  return D[m][n + 1]; } };
Exemple #6
0
std::vector<Simplex> Simplex::faces()  {
	std::vector<Simplex> all_faces;
	for(unsigned i = 0; i < simplex.size(); i++)  {
		std::vector<int> new_face;
		for(unsigned j = 0; j < simplex.size()-1; j++)  {
			int next_vertex = simplex[(j+i)%simplex.size()];
			new_face.push_back(next_vertex);
		}
		all_faces.push_back(Simplex(new_face,metric_space));
	}
	return all_faces;
}
Image* GenerateWoodSide(int width, int height){

	// Initialize Variables:
	Image *terrain = new Image(width, height); // Output Map
	double xValue, yValue, turb, distValue, sineValue;
	int value;
	const double PI = 3.141592653589793238463;

	double xyFactor = 2.0;	//Rings
	double turbFactor = 1.0 / 800.0;
	double turbPower = 0.05;
	int octaves = 10;


	// Initialize Simplex Generator:
	srand(time(0) ^ rand()); // Initialize Random Seed
	Simplex generator = Simplex();

	// Loops through all the pixels
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {

			xValue = (x + width) / ((double)width);
			yValue = (y - height / 2) / ((double)height);
			turb = turbPower*generator.Turbulence(x*turbFactor, y*turbFactor, octaves);
			distValue = (sqrt(xValue * xValue + yValue * yValue) + turb);
			sineValue = 128 * fabs(sin(2 * distValue*PI*xyFactor));


			// Convert the 0.0 to 1.0 noise value to a 0 to 255 RGB value:
			value = int(sineValue);
			if (value > 128)
				value = 128;
			else if (value < 0)
				value = 0;

			// Output heightmap to image:
			(*terrain)[y][x].red = 80 + value;
			(*terrain)[y][x].green = 30 + value;
			(*terrain)[y][x].blue = 30;
		}
	}

	return terrain;
}
Exemple #8
0
int main() {
/*
    Simplex::pivot_struct test_struct;
    Simplex::pivot_struct out_struct;

    test_struct.v=0;
    test_struct.N.insert(1);
    test_struct.N.insert(2);
    test_struct.N.insert(3);
    test_struct.B.insert(4);
    test_struct.B.insert(5);
    test_struct.B.insert(6);

    test_struct.c[1]=3;
    test_struct.c[2]=1;
    test_struct.c[3]=2;

    test_struct.b[4]=30;
    test_struct.b[5]=24;
    test_struct.b[6]=36;

    std::map<int,float> A_l1;
    std::map<int,float> A_l2;
    std::map<int,float> A_l3;

    test_struct.A[4]=A_l1;
    test_struct.A[5]=A_l2;
    test_struct.A[6]=A_l3;

    test_struct.A[4][1]=1;
    test_struct.A[5][1]=2;
    test_struct.A[6][1]=4;
    test_struct.A[4][2]=1;
    test_struct.A[5][2]=2;
    test_struct.A[6][2]=1;
    test_struct.A[4][3]=3;
    test_struct.A[5][3]=5;
    test_struct.A[6][3]=2;

    int e = 1;
    int l = 6;

    //std::cout << "Before Pivot" <<std::endl;

    //Simplex::print_pivot_struct(test_struct);

    out_struct = Simplex::pivot(test_struct,e,l);

    //std::cout << "After Pivot" <<std::endl;

    //Simplex::print_pivot_struct(out_struct);
*/

/*
    std::vector<float> b;
    b.push_back(30);
    b.push_back(24);
    b.push_back(36);
    std::vector<float> c;
    c.push_back(3);
    c.push_back(1);
    c.push_back(2);
    std::vector<std::vector<float>> A;
    A.push_back(std::vector<float> ());
    A.push_back(std::vector<float> ());
    A.push_back(std::vector<float> ());
    A[0].push_back(1);
    A[0].push_back(1);
    A[0].push_back(3);
    A[1].push_back(2);
    A[1].push_back(2);
    A[1].push_back(5);
    A[2].push_back(4);
    A[2].push_back(1);
    A[2].push_back(2);

    std::cout << "Create Simplex" <<std::endl;

    Simplex teste = Simplex(A,b,c);

    std::cout << "Print" <<std::endl;

    teste.print_internal_struct();

    std::vector<float> x = teste.solve();


    std::cout << "Solution" <<std::endl;

    for(auto i : x){
        std::cout << "x = " << i << std::endl;
    }



    std::cout << "Without initial feasible solution: " <<std::endl;

    std::vector<float> b1;
    b1.push_back(2);
    b1.push_back(-4);

    std::vector<float> c1;
    c1.push_back(2);
    c1.push_back(-1);

    std::vector<std::vector<float>> A1;
    A1.push_back(std::vector<float> ());
    A1.push_back(std::vector<float> ());
    A1[0].push_back(2);
    A1[0].push_back(-1);
    A1[1].push_back(1);
    A1[1].push_back(-5);

    Simplex teste1 = Simplex(A1,b1,c1);

    std::cout << "Print" <<std::endl;

    teste1.print_internal_struct();

    std::vector<float> x1 = teste1.solve();

    std::cout << "Solution" <<std::endl;

    std::cout << "Size: " << x1.size() << std::endl;

    for(auto i : x1){
        std::cout << "x = " << i << std::endl;
    }
    std::cout << std::endl<< std::endl;
*/
// TEST with Arduino LP

/*
# Created by Octave 3.8.1, Thu Dec 10 09:46:19 2015 WET <jmirandadealme@JMdeA-Zenbook>
# name: A
# type: matrix
# rows: 18
# columns: 9
 -10.21830350832508 -0.7271861952428118 -0.09748519653650334 -0.7271861952428118 -0.2769996701683155 -0.06890464691960219 -0.09748519653650334 -0.06890464691960219 -0.03280392761204531
 -0.7271861952428118 -10.21830350832508 -0.7271861952428118 -0.2769996701683155 -0.7271861952428118 -0.2769996701683155 -0.06890464691960219 -0.09748519653650334 -0.06890464691960219
 -0.09748519653650334 -0.7271861952428118 -10.21830350832508 -0.06890464691960219 -0.2769996701683155 -0.7271861952428118 -0.03280392761204531 -0.06890464691960219 -0.09748519653650334
 -0.7271861952428118 -0.2769996701683155 -0.06890464691960219 -10.21830350832508 -0.7271861952428118 -0.09748519653650334 -0.7271861952428118 -0.2769996701683155 -0.06890464691960219
 -0.2769996701683155 -0.7271861952428118 -0.2769996701683155 -0.7271861952428118 -10.21830350832508 -0.7271861952428118 -0.2769996701683155 -0.7271861952428118 -0.2769996701683155
 -0.06890464691960219 -0.2769996701683155 -0.7271861952428118 -0.09748519653650334 -0.7271861952428118 -10.21830350832508 -0.06890464691960219 -0.2769996701683155 -0.7271861952428118
 -0.09748519653650334 -0.06890464691960219 -0.03280392761204531 -0.7271861952428118 -0.2769996701683155 -0.06890464691960219 -10.21830350832508 -0.7271861952428118 -0.09748519653650334
 -0.06890464691960219 -0.09748519653650334 -0.06890464691960219 -0.2769996701683155 -0.7271861952428118 -0.2769996701683155 -0.7271861952428118 -10.21830350832508 -0.7271861952428118
 -0.03280392761204531 -0.06890464691960219 -0.09748519653650334 -0.06890464691960219 -0.2769996701683155 -0.7271861952428118 -0.09748519653650334 -0.7271861952428118 -10.21830350832508
 1 0 0 0 0 0 0 0 0
 0 1 0 0 0 0 0 0 0
 0 0 1 0 0 0 0 0 0
 0 0 0 1 0 0 0 0 0
 0 0 0 0 1 0 0 0 0
 0 0 0 0 0 1 0 0 0
 0 0 0 0 0 0 1 0 0
 0 0 0 0 0 0 0 1 0
 0 0 0 0 0 0 0 0 1
*/


 /*

# name: b
# type: matrix
# rows: 18
# columns: 1
 -2.234087037518483
 -6.370072142271482
 -2.314137495496334
 -4.195003918678363
 -2.89337934873546
 -7.706424278239382
 -7.357001197283779
 -5.483351507948527
 -7.286096857845781
 1
 1
 1
 1
 1
 1
 1
 1
 1
*/


/*
c =  -1  -1  -1  -1  -1  -1  -1  -1  -1
*/
/*
# name: random_pwm
# type: matrix
# rows: 9
# columns: 1
 0.1374661759009127
 0.5587605221930771
 0.1228113038292256
 0.3096195642559854
 0.104062656935522
 0.659452543924277
 0.6504349725253338
 0.4053939889252992
 0.6207688892129481

 Solution
x = 0.137466
x = 0.55876
x = 0.122811
x = 0.309627
x = 0.104059
x = 0.659453
x = 0.650444
x = 0.405394
x = 0.620769

*/

/*
std::vector<std::vector<float>> A2;
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());
A2.push_back(std::vector<float> ());

A2[0].push_back(-10.2183035083);
A2[0].push_back(-0.7271861952);
A2[0].push_back(-0.0974851965);
A2[0].push_back(-0.7271861952);
A2[0].push_back(-0.2769996702);
A2[0].push_back(-0.0689046469);
A2[0].push_back(-0.0974851965);
A2[0].push_back(-0.0689046469);
A2[0].push_back(-0.0328039276);

A2[1].push_back(-0.7271861952428118);
A2[1].push_back(-10.21830350832508);
A2[1].push_back(-0.7271861952428118);
A2[1].push_back(-0.2769996701683155);
A2[1].push_back(-0.7271861952428118);
A2[1].push_back(-0.2769996701683155);
A2[1].push_back(-0.06890464691960219);
A2[1].push_back(-0.09748519653650334);
A2[1].push_back(-0.06890464691960219);

A2[2].push_back(-0.09748519653650334);
A2[2].push_back(-0.7271861952428118);
A2[2].push_back(-10.21830350832508);
A2[2].push_back(-0.06890464691960219);
A2[2].push_back(-0.2769996701683155);
A2[2].push_back(-0.7271861952428118);
A2[2].push_back(-0.03280392761204531);
A2[2].push_back(-0.06890464691960219);
A2[2].push_back(-0.09748519653650334);

A2[3].push_back(-0.7271861952428118);
A2[3].push_back(-0.2769996701683155 );
A2[3].push_back(-0.06890464691960219);
A2[3].push_back(-10.21830350832508);
A2[3].push_back(-0.7271861952428118);
A2[3].push_back(-0.09748519653650334);
A2[3].push_back(-0.7271861952428118);
A2[3].push_back(-0.2769996701683155);
A2[3].push_back(-0.06890464691960219);

A2[4].push_back(-0.2769996701683155);
A2[4].push_back(-0.7271861952428118);
A2[4].push_back(-0.2769996701683155);
A2[4].push_back(-0.7271861952428118);
A2[4].push_back(-10.21830350832508);
A2[4].push_back(-0.7271861952428118);
A2[4].push_back(-0.2769996701683155);
A2[4].push_back(-0.7271861952428118);
A2[4].push_back(-0.2769996701683155);

A2[5].push_back(-0.06890464691960219);
A2[5].push_back(-0.2769996701683155);
A2[5].push_back(-0.7271861952428118);
A2[5].push_back(-0.09748519653650334);
A2[5].push_back(-0.7271861952428118);
A2[5].push_back(-10.21830350832508);
A2[5].push_back(-0.06890464691960219);
A2[5].push_back(-0.2769996701683155);
A2[5].push_back(-0.7271861952428118);

A2[6].push_back(-0.09748519653650334);
A2[6].push_back(-0.06890464691960219);
A2[6].push_back(-0.03280392761204531);
A2[6].push_back(-0.7271861952428118);
A2[6].push_back(-0.2769996701683155);
A2[6].push_back(-0.06890464691960219);
A2[6].push_back(-10.21830350832508);
A2[6].push_back(-0.7271861952428118);
A2[6].push_back(-0.09748519653650334);

A2[7].push_back(-0.06890464691960219);
A2[7].push_back(-0.09748519653650334);
A2[7].push_back(-0.06890464691960219);
A2[7].push_back(-0.2769996701683155);
A2[7].push_back(-0.7271861952428118);
A2[7].push_back(-0.2769996701683155);
A2[7].push_back(-0.7271861952428118);
A2[7].push_back(-10.21830350832508);
A2[7].push_back(-0.7271861952428118);

A2[8].push_back(-0.03280392761204531);
A2[8].push_back(-0.06890464691960219);
A2[8].push_back(-0.09748519653650334);
A2[8].push_back(-0.06890464691960219);
A2[8].push_back(-0.2769996701683155);
A2[8].push_back(-0.7271861952428118);
A2[8].push_back(-0.09748519653650334);
A2[8].push_back(-0.7271861952428118);
A2[8].push_back(-10.21830350832508);

A2[9].push_back(1);
A2[9].push_back(0);
A2[9].push_back(0);
A2[9].push_back(0);
A2[9].push_back(0);
A2[9].push_back(0);
A2[9].push_back(0);
A2[9].push_back(0);
A2[9].push_back(0);

A2[10].push_back(0);
A2[10].push_back(1);
A2[10].push_back(0);
A2[10].push_back(0);
A2[10].push_back(0);
A2[10].push_back(0);
A2[10].push_back(0);
A2[10].push_back(0);
A2[10].push_back(0);

A2[11].push_back(0);
A2[11].push_back(0);
A2[11].push_back(1);
A2[11].push_back(0);
A2[11].push_back(0);
A2[11].push_back(0);
A2[11].push_back(0);
A2[11].push_back(0);
A2[11].push_back(0);

A2[12].push_back(0);
A2[12].push_back(0);
A2[12].push_back(0);
A2[12].push_back(1);
A2[12].push_back(0);
A2[12].push_back(0);
A2[12].push_back(0);
A2[12].push_back(0);
A2[12].push_back(0);

A2[13].push_back(0);
A2[13].push_back(0);
A2[13].push_back(0);
A2[13].push_back(0);
A2[13].push_back(1);
A2[13].push_back(0);
A2[13].push_back(0);
A2[13].push_back(0);
A2[13].push_back(0);

A2[14].push_back(0);
A2[14].push_back(0);
A2[14].push_back(0);
A2[14].push_back(0);
A2[14].push_back(0);
A2[14].push_back(1);
A2[14].push_back(0);
A2[14].push_back(0);
A2[14].push_back(0);

A2[15].push_back(0);
A2[15].push_back(0);
A2[15].push_back(0);
A2[15].push_back(0);
A2[15].push_back(0);
A2[15].push_back(0);
A2[15].push_back(1);
A2[15].push_back(0);
A2[15].push_back(0);

A2[16].push_back(0);
A2[16].push_back(0);
A2[16].push_back(0);
A2[16].push_back(0);
A2[16].push_back(0);
A2[16].push_back(0);
A2[16].push_back(0);
A2[16].push_back(1);
A2[16].push_back(0);

A2[17].push_back(0);
A2[17].push_back(0);
A2[17].push_back(0);
A2[17].push_back(0);
A2[17].push_back(0);
A2[17].push_back(0);
A2[17].push_back(0);
A2[17].push_back(0);
A2[17].push_back(1);


std::vector<float> b2;
b2.push_back(-2.234087037518483);
b2.push_back(-6.370072142271482);
b2.push_back(-2.314137495496334);
b2.push_back(-4.195003918678363);
b2.push_back(-2.89337934873546);
b2.push_back(-7.706424278239382);
b2.push_back(-7.357001197283779);
b2.push_back(-5.483351507948527);
b2.push_back(-7.286096857845781);
b2.push_back(1);
b2.push_back(1);
b2.push_back(1);
b2.push_back(1);
b2.push_back(1);
b2.push_back(1);
b2.push_back(1);
b2.push_back(1);
b2.push_back(1);

std::vector<float> c2;
c2.push_back(-1);
c2.push_back(-1);
c2.push_back(-1);
c2.push_back(-1);
c2.push_back(-1);
c2.push_back(-1);
c2.push_back(-1);
c2.push_back(-1);
c2.push_back(-1);



    Simplex teste2 = Simplex(A2,b2,c2);

    std::cout << "Print" <<std::endl;

    teste2.print_internal_struct();

    std::vector<float> x2 = teste2.solve();

    std::cout << "Solution" <<std::endl;

    for(auto i : x2){
        std::cout << "x = " << i << std::endl;
    }
*/

/*    // Mr Silva test, lab 12:

    std::vector<std::vector<float>> A3;
    A3.push_back(std::vector<float> ());
    A3.push_back(std::vector<float> ());
    A3.push_back(std::vector<float> ());
    A3[0].push_back(2);
    A3[0].push_back(1);
    A3[1].push_back(4);
    A3[1].push_back(3);


    std::vector<float> b3;
    b3.push_back(100);
    b3.push_back(240);

    std::vector<float> c3;
    c3.push_back(7);
    c3.push_back(5);




    Simplex teste3 = Simplex(A3,b3,c3);

    std::cout << "Print" <<std::endl;

    teste3.print_internal_struct();

    std::vector<float> x3 = teste3.solve();

    std::cout << "Solution" <<std::endl;

    for(auto i : x3){
        std::cout << "x = " << i << std::endl;
    }
*/

    // Mr Silva with unnecessary constrain
/*
    std::vector<std::vector<float>> A4;
    A4.push_back(std::vector<float> ());
    A4.push_back(std::vector<float> ());
    A4.push_back(std::vector<float> ());
    A4[0].push_back(-1);
    A4[0].push_back(0);
    A4[1].push_back(2);
    A4[1].push_back(1);
    A4[2].push_back(4);
    A4[2].push_back(3);



    std::vector<float> b4;
    b4.push_back(-20);
    b4.push_back(100);
    b4.push_back(240);

    std::vector<float> c4;
    c4.push_back(7);
    c4.push_back(5);




    Simplex teste4 = Simplex(A4,b4,c4);
    std::cout << "Print" <<std::endl;

    teste4.print_internal_struct();

    std::vector<float> x4 = teste4.solve();

    std::cout << "Solution" <<std::endl;

    for(auto i : x4){
        std::cout << "x = " << i << std::endl;
    }

*/


/*
N = {2,5,}
B = {1,3,4,}
A = {
0,-1,
1,2,
3,4,
}
b = {20,60,160,}
c = {5,7,}
v = 140
*/

/*
std::vector<std::vector<float>> A5;
A5.push_back(std::vector<float> ());
A5.push_back(std::vector<float> ());
A5.push_back(std::vector<float> ());
A5[0].push_back(0);
A5[0].push_back(-1);
A5[1].push_back(1);
A5[1].push_back(2);
A5[2].push_back(3);
A5[2].push_back(4);


std::vector<float> b5;
b5.push_back(20);
b5.push_back(60);
b5.push_back(160);

std::vector<float> c5;
c5.push_back(5);
c5.push_back(7);


Simplex teste5 = Simplex(A5,b5,c5);
std::vector<float> x5 = teste5.solve();

std::cout << "Solution" <<std::endl;

for(auto i : x5){
    std::cout << "x = " << i << std::endl;
}
*/


/*isto é para aberto

O_vals: 198 236 260
E_vals:
708 275 269
579 640 284
380 560 581
*/
  /*
std::vector<std::vector<float>> E;
std::vector<float> O;
std::vector<float> L;
E.push_back(std::vector<float>());
E.push_back(std::vector<float>());
E.push_back(std::vector<float>());
O.push_back(198.0/1024);
O.push_back(236.0/1024);
O.push_back(260.0/1024);
L.push_back(600.0/1024);
L.push_back(600.0/1024);
L.push_back(600.0/1024);
E[0].push_back(708.0/1024);
E[0].push_back(275.0/1024);
E[0].push_back(269.0/1024);
E[1].push_back(579.0/1024);
E[1].push_back(640.0/1024);
E[1].push_back(284.0/1024);
E[2].push_back(380.0/1024);
E[2].push_back(560.0/1024);
E[2].push_back(581.0/1024);

lp_struct lp = generate_linear_programm(E,O,L);

Simplex teste = Simplex(lp.A,lp.b,lp.c);

std::vector<float> x = teste.solve();

for(auto i : x){
    std::cout << "x = " << i*255 << std::endl;
}
*/

/*fechado

O_vals: 5 3 3
E_vals:
745 137 67
598 704 113
317 586 674*/

std::vector<std::vector<float>> E;
std::vector<float> O;
std::vector<float> L;
E.push_back(std::vector<float>());
E.push_back(std::vector<float>());
E.push_back(std::vector<float>());
O.push_back(5.0/1024);
O.push_back(3.0/1024);
O.push_back(3.0/1024);
L.push_back(600.0/1024);
L.push_back(600.0/1024);
L.push_back(600.0/1024);
E[0].push_back(745.0/1024);
E[0].push_back(137.0/1024);
E[0].push_back(67.0/1024);
E[1].push_back(598.0/1024);
E[1].push_back(704.0/1024);
E[1].push_back(113.0/1024);
E[2].push_back(317.0/1024);
E[2].push_back(586.0/1024);
E[2].push_back(674.0/1024);

lp_struct lp = generate_linear_programm(E,O,L);

Simplex teste = Simplex(lp.A,lp.b,lp.c);

std::vector<float> x = teste.solve();

for(auto i : x){
  std::cout << "x = " << i*255 << std::endl;
}

}
int main() {
Data();
Simplex();
Results();
}