void qrdecmp(double *E, int *E_dim, int *setp, int *oldsetp, double *u)
{
/* series of Householder tranformation designed specifically for the LS problem */
	int setlength = 0, added = 1, removed;
	double b;
	
	while((setlength<E_dim[1]-1)&&(setp[setlength]!=0)&&(oldsetp[setlength]!=0))
			setlength++;
/* find a zero to either setp or oldsetp */
	
	if(setp[setlength]==0)
		added = 0;
	
	if(added == 1)
/* householder transformation to most recently chosen column, setp[setlength] in the matrix */
	{
		b = house(setp[setlength],setlength,E,E_dim,u);
		orthomult(E,E_dim,u,b);
	}
	else
/* householder transformation to all columns listed in setp */
	{
		removed = 0;
		while((removed<E_dim[1]-1)&&(setp[removed] == oldsetp[removed]))
			removed++;
		while((removed<E_dim[1]-1)&&(setp[removed] != 0))
		{
				b = house(setp[removed],removed,E, E_dim,u);
				orthomult(E,E_dim,u,b);
				removed++;
		}
	}
}
Пример #2
0
mat ls_solve_od(const mat &A, const mat &B)
{
    int m=A.rows(), n=A.cols(), N=B.cols(), j;
    double beta;
    mat A2(A), B2(B), B3(n,N), submat, submat2;
    vec tmp(n), v;

//    it_assert1(m >= n, "The system is under-determined!");
    //it_assert1(m == B.rows(), "The number of rows in A must equal the number of rows in B!");

    // Perform a Householder QR factorization
    for (j=0; j<n; j++) {
	house(rvectorize(A2(j, m-1, j, j)), v, beta);
	v *= sqrt(beta);
	// 	submat.ref(A2, j,m-1, j,n-1);
 	submat = A2(j,m-1,j,n-1);
	sub_v_vT_m(submat, v);
	// 	submat.ref(B2, j,m-1, 0,N-1);
 	submat = B2(j,m-1,0,N-1);
	sub_v_vT_m(submat, v);
    }

    //    submat.ref(A2, 0,n-1,0,n-1);
    //    submat2.ref(B2, 0,n-1,0,N-1);
    submat = A2(0,n-1,0,n-1);
    submat2 = B2(0,n-1,0,N-1);
    for (j=0; j<N; j++) {
	backward_substitution(submat, submat2.get_col(j), tmp);
	B3.set_col(j, tmp);
    }
    
    return B3;
}
Пример #3
0
void GameOfLife::control_Movie ( wchar_t **nextLattice )
{
  if ( m_time %3 ==0 )
    {

      if ( carx < m_w-5 )
        {
          carx += 2;
        }
      else
        {
          carx = 0;
        }
    }

  if ( m_time %6 ==0 )
    {
      if ( manx < m_w-3 )
        {
          ++manx;
        }
      else
        {
          manx = 0;
        }
    }

  house ( nextLattice, housex, 3*m_h/5 -6 );
  car ( nextLattice, carx, 3*m_h/5 +1 );
  man ( nextLattice, manx, 3*m_h/5-1 );

}
Пример #4
0
void test() {
    // implement tests
    double mwst = 19;
    std::string carText = "A nice car";
    Amount car(115, mwst, carText);
    assert(car.netto() == 115);
    assert(car.mwst() == 19);
    assert(carText.compare(car.text()) == 0);
    assert(car.currency() == Amount::Currency::EUR);
    assert(almost_equals(car.mwst_amount(), 21.85));
    car.currency(Amount::Currency::USD);
    assert(almost_equals(car.brutto(), 150.535));
    assert(car.currency() == Amount::Currency::USD);
    car.currency(Amount::Currency::USD);
    assert(almost_equals(car.brutto(), 150.535));
    assert(almost_equals(car.netto(), 126.5));
    car.currency(Amount::Currency::EUR);
    assert(almost_equals(car.netto(), 115));
    assert(car.currency() == Amount::Currency::EUR);

    std::string houseText = "A huge house";
    Amount house(2000, mwst, houseText, Amount::Currency::USD);
    assert(house.currency() == Amount::Currency::USD);
    assert(house.netto() == 2000);
}
Пример #5
0
int main()
{
    Husband h;
    Wife w;
    clrscr();

//    int gd=DETECT,gm;
    initgraph(&gdriver,&gmode,"c:\\Turboc3\\bgi");
    int waitCount=5,j=10;
    house();

    h.wait();
    while(waitCount!=0)
    {
     w.wait();
     husFace(-j);
     sleep(1);
     waitCount--;
     j=j+30;
     }
    h.signal();
    w.signal();


getch();
return 0;
}
Пример #6
0
void GameOfLife::control_Movie ( int **nextLattice, int mode )
{
  if ( m_time %3 ==0 )
    {

      if ( carx < m_w-5 )
        {
          carx += 2;
        }
      else
        {
          carx = 0;
        }
    }

  if ( m_time %6 ==0 )
    {
      if ( manx < m_w-3 )
        {
          ++manx;
        }
      else
        {
          manx = 0;
        }
    }

  if ( mode == 1 )
    {
      house ( nextLattice, housex, 3*m_h/5 -6 );
    }
  else if ( mode == 2 )
    {
      car ( nextLattice, carx, 3*m_h/5 +1 );
    }
  else if ( mode == 3 )
    {
      man ( nextLattice, manx, 3*m_h/5-1 );
    }
  else
    {
      house ( nextLattice, housex, 3*m_h/5 -6 );
      car ( nextLattice, carx, 3*m_h/5 +1 );
      man ( nextLattice, manx, 3*m_h/5-1 );
    }

}
void qrfactor(matrix & Q, matrix & R, matrix & betas, const matrix & A){
  int i, j, k, l, N, M; i = 0; j = 0; k = 0; l = 0; N = 0; M = 0;
  fpp beta, temp; beta = 0.0; temp = 0.0;

  N = A.get_rows(); M = A.get_cols();

  matrix bigV(N,1), temp_row(N,1); zeros(bigV); zeros(temp_row);
  submatrix x, v;

  if((Q.get_rows() != N) || (Q.get_cols() != M) ||(R.get_rows() != N) || (R.get_cols() != M) || (betas.get_rows() != A.get_rows()) || (betas.get_cols() != 1)){
    std::cerr << "QR dimensions incompatible! Q(" << Q.get_rows() << "," << Q.get_cols() << "), R(" << R.get_rows() << "," << R.get_cols() << "), betas:(" << betas.get_rows() << "," << betas.get_cols() << "), A:(" << A.get_rows() << "," << A.get_cols() << ")." << std::endl;
    exit(-1);
  }

  R = A;
  zeros(Q);

  for(i = 0; i < N; i++){
    Q(i,i) = 1.0;
  }

  for(i = 0; i < N-1; i++){
    x.subcreate(R, i, i, N-i, 1);
    v.subcreate(bigV, i, 0, N-i, 1);
    house(v,beta,x);

    for(k = i; k < M; k++){
      for(j = i; j < N; j++){
	temp = 0.0;
	for(l = i; l < N; l++){
	  temp += beta*v(l-i,0)*v(j-i,0)*R(l,k);
	}
	temp_row(j,0) = R(j,k) - temp;
      }
      for(l = i; l < N; l++){
	R(l,k) = temp_row(l,0);
      }
    }

    for(k = 0; k < M; k++){
      for(j = i; j < N; j++){
	temp = 0.0;
	for(l = i; l < N; l++){
	  temp += beta*v(l-i,0)*v(j-i,0)*Q(l,k);
	}
	temp_row(j,0) = Q(j,k) - temp;
      }
      for(l = i; l < N; l++){
	Q(l,k) = temp_row(l,0);
      }
    }

    betas(i,0) = beta;
  }

} 
int ias_math_matrix_QRfactorization
(
    double *A,     /* I/O: Matrix A (stored by columns)     */
    int m,         /* I: Number of rows in matrix A         */
    int n,         /* I: Number of columns in matrix A      */
    double *v,     /* O: Vector v (work vector)             */
    int flag       /* I: If true, order matrix A by columns */
)
{
    int  N;                 /* Maximum loop iteration                        */
    int  i, j, k;           /* Loop counters                                 */
    double *cur_col_A;      /* Pointer to current column of matrix A         */
    double vtv, temp;       /* Temporary variables                           */

    /* By default, matrix A is assumed to be ordered by columns (that is, in
       column major form.)  If "flag" is set, the caller has passed the matrix
       in row major, so reorder the matrix so that we can work with it. */
    if (flag)
    {
        for (i = 0; i < m; i++)
        {
            for (j = i + 1; j < n; j++)
            {      
                k = (i * n) + j;
                temp = A[k];   
                A[k] = A[(j * n) + i];
                k = (j * n) + i;
                A[k] = temp;
            }
        }
    }

    /* Determine the maximum looping factor */
    N = ((m - 1) > n) ? n : (m - 1);

    for (k = 0; k < N; ++k)
    {
        cur_col_A = A + (k * m);
        /* Determine the Householder Transformation in vector v for a row in 
           the input vector A */
        house((m - k), &(cur_col_A[k]), &(v[k]), &vtv, &(cur_col_A[k]));

        for (j = k + 1; j < m; j++)
            cur_col_A[j] = v[j];

        /* Replace the m by n matrix A by the product vA. */
        row_house(&(A[(k + 1) * m + k]), (m - k), (n - k - 1), m, &(v[k]), vtv);
        v[k] = vtv;  
    } 

    return SUCCESS;
}
Пример #9
0
void forest (int n) //N - количество елочек в лесу
{
 int h0=150;
 int i,a,b,h;
 int col;
 for (i=1; i<=n; i++)
    {
      h=rand()%h0+10;           // высота треугольника от 10 до h0 точек
      a=rand()%700;  // координата x вершины елочки - от 20 до ширины окна
      b=rand()%500;  // координата y вершины елочки - от 5 до высоты окна
      col=rand()%15+1;           // цвет линий
      fir(a,b,h,col); 	// ќбращение к процедуре рисовани¤ елочки
      car(a, b);
      house(a, b);
    }
}
Пример #10
0
void generateBuildings (Context& context,
                        std::vector<BuildingSeed>& seeds,
                        std::vector<Cuboid>& houses) {
    for (std::vector<BuildingSeed>::iterator it = seeds.begin();
         it != seeds.end();
         it++) {
        BuildingSeed & bs = *it;

        glm::vec2 road = bs.closest_road_point;
        glm::vec2 u = glm::normalize(road - bs.location);
        glm::vec3 pos = glm::vec3(bs.location.x, context.terrain->getHeight(bs.location), bs.location.y);
        CoordSystem cs = CoordSystem::fromVectors(pos,
                                                  glm::vec3(u.x, 0, u.y),
                                                  glm::vec3(-u.y, 0, u.x));
        /* float alpha = zHouse / 2; */
        /* cs.position = pos - alpha * glm::vec3(u.x, 0, u.y); */
        cs.position = pos;
        glm::vec3 dimensions(xHouse, yHouse, zHouse);
        Cuboid maison(cs, dimensions);
        Rectangle2D house(cs, dimensions.x, dimensions.z);

        bool inserted = true;

        // Collision muraille / maison
        if (intersect_rect_poly(context,
                                house,
                                context.strongholds[context.currentStronghold].base)) {
            inserted = false;
        }

        // Collisions entre maisons
        for (int i = 0; i < houses.size(); i++) {
            Rectangle2D house2(houses[i].getCoordSystem(),
                               houses[i].dimensions.x,
                               houses[i].dimensions.z);
            if (intersect_houses(house, house2)) {
                inserted = false;
                break;
            }
        }

        if (inserted) {
            houses.push_back(maison);
        }
    }
}
Пример #11
0
void tridiagonalize(int n, matrix a, vector d, vector e)
{
	int i, j, k;
	double s, t, p, q;
	vector v, w;

	for (k = 0; k < n - 2; k++) {
		v = a[k];  d[k] = v[k];
		e[k] = house(n - k - 1, &v[k + 1]);
		if (e[k] == 0) continue;
		for (i = k + 1; i < n; i++) {
			s = 0;
			for (j = k + 1; j < i; j++) s += a[j][i] * v[j];
			for (j = i;     j < n; j++) s += a[i][j] * v[j];
			d[i] = s;
		}
		t = innerproduct(n-k-1, &v[k+1], &d[k+1]) / 2;
		for (i = n - 1; i > k; i--) {
			p = v[i];  q = d[i] - t * p;  d[i] = q;
			for (j = i; j < n; j++)
				a[i][j] -= p * d[j] + q * v[j];
		}
	}
	if (n >= 2) {  d[n - 2] = a[n - 2][n - 2];
	               e[n - 2] = a[n - 2][n - 1];  }
	if (n >= 1)    d[n - 1] = a[n - 1][n - 1];
	for (k = n - 1; k >= 0; k--) {
		v = a[k];
		if (k < n - 2) {
			for (i = k + 1; i < n; i++) {
				w = a[i];
				t = innerproduct(n-k-1, &v[k+1], &w[k+1]);
				for (j = k + 1; j < n; j++)
					w[j] -= t * v[j];
			}
		}
		for (i = 0; i < n; i++) v[i] = 0;
		v[k] = 1;
	}
}
Пример #12
0
vec ls_solve_od(const mat &A, const vec &b)
{
    int m=A.rows(), n=A.cols();
    double beta;
    mat A2(A), submat;
    vec b2(b), v;

//    it_assert1(m >= n, "The system is under-determined!");
//    it_assert1(m == b.size(), "The number of rows in A must equal the length of b!");
    
    // Perform a Householder QR factorization
    for (int j=0; j<n; j++) {
	house(rvectorize(A2(j, m-1, j, j)), v, beta);
	v *= sqrt(beta);
	// 	submat.ref(A2, j,m-1, j,n-1);
 	submat = A2(j,m-1,j,n-1); // Time-consuming
	sub_v_vT_m(submat, v);
	b2.set_subvector(j,m-1, b2(j,m-1)- v*(v*b2(j,m-1)));
    }

    return backward_substitution(A2(0,n-1,0,n-1), b2(0,n-1));
}
Пример #13
0
int main(int argc, char **argv)
{
	int i,j,N,row,col,n,k,q;
	double *P,*bvec,*R,*Q;
	N = 4;
	double b;
	b = 1.;
	row = 3;
	col = 3;
	P = (double*) malloc(sizeof(double) * N * N);
	//AA = (double*) malloc(sizeof(double) * row * col);
	bvec = (double*) malloc(sizeof(double) * col);
	R = (double*) malloc(sizeof(double) * col *col);
	Q = (double*) malloc(sizeof(double) * row * col);
	double x[4] = {3,1,5,1};
	double v[4] = {0,0,0,0};
	double AA[9] = {12,-51,4,6,167,-68,-4,24,-41};
	printf("b %lf \n", b);
	b = house(x,N,v);
	printf("beta %lf \n",b);
	
	for(i =0;i < N;++i) {
		printf("v %lf \n",v[i]);
	}
	housemat(v,N,b,P);
	mdisplay(P,N,N);
	
	mmult(P,x,v,N,N,1);
	mdisplay(v,N,1);
	
	
	qr_house(AA,row,col,bvec);
	mdisplay(AA,row,col);
	getQR_house(AA,row,col,bvec,Q,R);
	mdisplay(R,col,col);
	mdisplay(Q,row,col);
	
	mmult(Q,R,AA,row,col,col);
	mdisplay(AA,row,col);
	double A[9] = {1,5,7,3,0,6,4,3,1};
	//double A[16] = {4,1,-1,2,1,4,1,-1,-1,1,4,1,2,-1,1,4};
	double H[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	double eigre[3] = {0,0,0,0};
	double eigim[3] = {0,0,0,0};

	/*
	francis_iter(A,4,H);
	mdisplay(H,4,4);
	double eigre[2] = {0,0};
	double eigim[2] = {0,0};
	eig22(H,4,eigre,eigim);
	 * 
	printf("e0 %lf %lf \n",eigre[0],eigim[0]);
	printf("e1 %lf %lf \n",eigre[1],eigim[1]);
	 */
	eig(A,3,eigre,eigim);
	
	for(i=0; i < 3;++i) {
		printf("e%d %g %g \n",i,eigre[i],eigim[i]);
	}
	
	free(P);
	//free(AA);
	free(bvec);
	free(R);
	free(Q);
	
	return 0;
}
Пример #14
0
void display()
{

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
	GLfloat mat_diffuse[] = { 0.5, 0.5, 0.5, 1.0 };
	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat mat_shininess[] = { 50.0 };
	GLfloat lightintensity[] = { 1, 1, 1, 1.0 };
	GLfloat lightposition[] = { 2.0, 2.0, 2.0, 1.0 };
	GLfloat lightposition2[] = { -2.0, -2.0, -2.0, 1.0 };
	glClearColor(0.5, 0.5, 0.5, 0.0);
	switch (back)
	{
	case 1:     glClearColor(1.0, 0.0, 0.0, 0.0);
		break;
	case 2:     glClearColor(0.0, 0.0, 1.0, 0.0);
		break;
	case 3:    glClearColor(0.0, 1.0, 0.0, 0.0);
		break;
	case 4:    glClearColor(0.0, 0.0, 0.0, 0.0);
		break;
	}

	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

	glLightfv(GL_LIGHT0, GL_POSITION, lightposition);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightintensity);
	glLightfv(GL_LIGHT0, GL_SPECULAR, mat_specular);
	glLightfv(GL_LIGHT1, GL_POSITION, lightposition2);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, lightintensity);
	glLightfv(GL_LIGHT1, GL_SPECULAR, mat_specular);

	if (lightflag)   glEnable(GL_LIGHTING);
	else glDisable(GL_LIGHTING);
	
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_NORMALIZE);
	glEnable(GL_COLOR_MATERIAL);
	
	if (orthoflag)
	{
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(-1, 1, -1, 1, -20, 20);
		glMatrixMode(GL_MODELVIEW);
	}
	else
	{
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10.0);
		glMatrixMode(GL_MODELVIEW);
	}

	glLoadIdentity();
	gluLookAt(viewer[0], viewer[1], viewer[2], 0, 0, 0, 0, 1, 0);
	glRotatef(theta[0], 1, 0, 0);
	glRotatef(theta[1], 0, 1, 0);
	glRotatef(theta[2], 0, 0, 1);

	house(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);
	htop(h[0], h[1], h[2], h[3], h[4]);
	tv(t[0], t[1], t[2], t[3]);
	tvs(ts[0], ts[1], ts[2], ts[3], ts[4], ts[5], ts[6], ts[7]);
	grass();
	sofa1();
	rainwater();
	sump();
	table();
	teapot();
	tree();
	compound();
	window();
	housefront(hfrt[0], hfrt[1], hfrt[2], hfrt[3]);
	fan(f[0], f[1], f[2], f[3], f[4], f[5]);
	fblade(fb[0], fb[1], fb[2], fb[3], fb[4], fb[5], fb[6], fb[7], fb[8], fb[9], fb[10], fb[11], fb[12], fb[13], fb[14], fb[15]);

	glEnable(GL_DEPTH_TEST);
	glutSwapBuffers();
}
Пример #15
0
void GameOfLife::development()
{

  bool **prevLattice = lattices[latticeIndex];
  bool **nextLattice = lattices[ ( latticeIndex+1 ) %2];

  /*
  for ( int i {0}; i<m_h; ++i )
    {
      for ( int j {0}; j<m_w; ++j )
        {

          int liveNeighbors = numberOfNeighbors ( prevLattice, i, j, true );

          if ( prevLattice[i][j] == true )
            {
              if ( liveNeighbors==2 || liveNeighbors==3 )
                {
                  nextLattice[i][j] = true;
                }
              else
                {
                  nextLattice[i][j] = false;
                }
            }
          else
            {
              if ( liveNeighbors==3 )
                {
                  nextLattice[i][j] = true;
                }
              else
                {
                  nextLattice[i][j] = false;
                }
            }
        }
    }
    */

  for ( int i {0}; i<m_h; ++i )
    {
      for ( int j {0}; j<m_w; ++j )
        {

          nextLattice[i][j] = false;

        }
    }

  if(m_time %3 ==0)
  {

    if ( carx < m_w-5 )
    carx += 2;
  else
    carx = 0;
  }
  
  if(m_time %6 ==0)
  {
  if ( manx < m_w-3 )
    ++manx;
  else
    manx = 0;
  }
  
  house ( nextLattice, housex, 3*m_h/5 -6 );
  car ( nextLattice, carx, 3*m_h/5 +1 );
  man ( nextLattice, manx, 3*m_h/5-1 );
  
}
Пример #16
0
void MakeHouse(IloModel model,
               IloNumExpr cost,
               IloIntervalVarArray allTasks,
               IloIntervalVarArray joeTasks,
               IloIntervalVarArray jimTasks,
               IloIntArray joeLocations,
               IloIntArray jimLocations,
               IloInt loc,
               IloInt rd,
               IloInt dd,
               IloNum weight) {
    IloEnv env = model.getEnv();

    /* CREATE THE INTERVALS VARIABLES. */
    char name[128];

    IloIntervalVarArray tasks(env, NbTasks);
    for (IloInt i=0; i<NbTasks; ++i) {
        sprintf(name, "H%ld-%s", loc, TaskNames[i]);
        tasks[i] = IloIntervalVar(env, TaskDurations[i], name);
        allTasks.add(tasks[i]);
    }

    /* SPAN CONSTRAINT. */
    sprintf(name, "H%ld", loc);
    IloIntervalVar house(env, name);
    model.add(IloSpan(env, house, tasks));

    /* ADDING PRECEDENCE CONSTRAINTS. */
    house.setStartMin(rd);
    model.add(IloEndBeforeStart(env, tasks[masonry],   tasks[carpentry]));
    model.add(IloEndBeforeStart(env, tasks[masonry],   tasks[plumbing]));
    model.add(IloEndBeforeStart(env, tasks[masonry],   tasks[ceiling]));
    model.add(IloEndBeforeStart(env, tasks[carpentry], tasks[roofing]));
    model.add(IloEndBeforeStart(env, tasks[ceiling],   tasks[painting]));
    model.add(IloEndBeforeStart(env, tasks[roofing],   tasks[windows]));
    model.add(IloEndBeforeStart(env, tasks[roofing],   tasks[facade]));
    model.add(IloEndBeforeStart(env, tasks[plumbing],  tasks[facade]));
    model.add(IloEndBeforeStart(env, tasks[roofing],   tasks[garden]));
    model.add(IloEndBeforeStart(env, tasks[plumbing],  tasks[garden]));
    model.add(IloEndBeforeStart(env, tasks[windows],   tasks[moving]));
    model.add(IloEndBeforeStart(env, tasks[facade],    tasks[moving]));
    model.add(IloEndBeforeStart(env, tasks[garden],    tasks[moving]));
    model.add(IloEndBeforeStart(env, tasks[painting],  tasks[moving]));

    /* ALLOCATING TASKS TO WORKERS. */
    joeTasks.add(tasks[masonry]);
    joeLocations.add(loc);
    joeTasks.add(tasks[carpentry]);
    joeLocations.add(loc);
    jimTasks.add(tasks[plumbing]);
    jimLocations.add(loc);
    jimTasks.add(tasks[ceiling]);
    jimLocations.add(loc);
    joeTasks.add(tasks[roofing]);
    joeLocations.add(loc);
    jimTasks.add(tasks[painting]);
    jimLocations.add(loc);
    jimTasks.add(tasks[windows]);
    jimLocations.add(loc);
    joeTasks.add(tasks[facade]);
    joeLocations.add(loc);
    joeTasks.add(tasks[garden]);
    joeLocations.add(loc);
    jimTasks.add(tasks[moving]);
    jimLocations.add(loc);

    /* DEFINING MINIMIZATION OBJECTIVE. */
    cost += TardinessCost(house, dd, weight);
    cost += IloLengthOf(house);
}
Пример #17
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (mode)
   {
      double Ex = -2*dim*Sin(th)*Cos(ph);
      double Ey = +2*dim        *Sin(ph);
      double Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }
   
   house(-1,0,1,0.3,0.3,0.3,0);
   house(-1,0,-1,0.3,0.3,0.3,90);
   house(1,0,-1,0.3,0.3,0.3,180);
   house(1,0,1,0.3,0.3,0.3,270);

   house(-3,0,3,1,0.3,0.3,0);
   house(-3,.5,-3,0.3,1,0.3,0);
   house(3,0,-3,0.3,0.3,1,180);
   house(3,0,3,1,0.3,1,270);

   house(0,0,3,.3,.5,.5,0);
   house(0,0,-3,1.2,.5,.5,0);
   house(3,0,0,.5,.5,.3,270);

   //  Display parameters
   glWindowPos2i(5,5);
   Print("Angle=%d,%d  Dim=%.1f FOV=%d Projection=%s",th,ph,dim,fov,mode?"Perpective":"Orthogonal");
   //  Render the scene and make it visible
   glFlush();
   glutSwapBuffers();
}
Пример #18
0
//****************************************对抽取的语料库按类别进行分类****************************************
void corpus_category(string filename_path, string path_read, string path_write) //参数1:文件名列表路径 参数2:读取文件的目录 参数3:写入文件的目录
{

	string file_name;    //存储读取的各个文件的名字
	ifstream read_filename(filename_path);  //从LIST.TXT读取文件名
	ofstream sports(path_write+"sports.txt");//属于sport类的存放在sport.txt文件中
	ofstream house(path_write+"house.txt");
	ofstream it(path_write+"it.txt");
	ofstream test_2008(path_write+"2008.txt");
	ofstream news(path_write+"news.txt");
	ofstream yule(path_write+"yule.txt");
	ofstream business(path_write+"business.txt");
	ofstream travel(path_write+"travel.txt");
	ofstream mil_news(path_write+"mil.news.txt");
	ofstream women(path_write+"women.txt");
	ofstream health(path_write+"health.txt");
	ofstream test_auto(path_write+"auto.txt");
	ofstream cul(path_write+"cul.txt");
	ofstream learning(path_write+"learning.txt");
	ofstream test_else(path_write+"else.txt");
	string path_in, str_line,cut_str;//path_in:存放读文件路径 str_line:读取的一行文件 cut_str:存放截取的字符串
	string::size_type pos1, pos2;
	int number = 0;
	while (getline(read_filename, file_name))
	{
		number++;
		cout << number << endl;
		path_in = path_read + file_name;
		ifstream infile(path_in);
		while (getline(infile, str_line))              //读取各个文件的每一行字符串
		{
			pos1 = 0;
			pos2 = str_line.find("####");
			cut_str = str_line.substr(pos1, pos2 - pos1);
			if (string(cut_str) == string("sports"))         //字符串匹配  是否为sports类
			{
				sports << str_line << endl;                  //如果是sports类就把该行输出到sports.txt文件
			}
			else if (cut_str == "house")
			{
				house << str_line << endl;
			}
			else if (cut_str == "it")
			{
				it << str_line << endl;
			}
			else if (cut_str == "2008")
			{
				test_2008 << str_line << endl;
			}
			else if (cut_str == "news")
			{
				news << str_line << endl;
			}
			else if (cut_str == "yule")
			{
				yule << str_line << endl;
			}
			else if (cut_str == "business")
			{
				business << str_line << endl;
			}
			else if (cut_str == "travel")
			{
				travel << str_line << endl;
			}
			else if (cut_str == "mil.news")
			{
				mil_news << str_line << endl;
			}
			else if (cut_str == "women")
			{
				women << str_line << endl;
			}
			else if (cut_str == "health")
			{
				health << str_line << endl;
			}
			else if (cut_str == "auto")
			{
				test_auto << str_line << endl;
			}
			else if (cut_str == "cul")
			{
				cul << str_line << endl;
			}
			else if (cut_str == "learning")
			{
				learning << str_line << endl;
			}
			else
			{
				test_else << str_line << endl;
			}
		}
		infile.close();   //每次结束都得关闭文件.
	}
}