Пример #1
0
int main(int argc, char* argv[]) {
    // No file name given
    if (argc < 2) {
        std::cout << "You need to specify an input file name" << std::endl;
        return -10;
    }
    // Make 3 copies of the process list
    std::vector<Process> processes = wr::getFileData(argv[1]);
    std::vector<Process> procCopy1(processes);
    std::vector<Process> procCopy2(processes);
    // Make 3 virtual machines and give them schedulers
    Machine vm1(processes);
    Machine vm2(procCopy1);
    Machine vm3(procCopy2);
    FCFS fcfsAlg;
    SRTF srtfAlg;
    RR rrAlg;
    vm1.setSchedulingAlgorithm(&fcfsAlg);
    vm2.setSchedulingAlgorithm(&srtfAlg);
    vm3.setSchedulingAlgorithm(&rrAlg);
    // Start the machines
    vm1.start();
    vm2.start();
    vm3.start();
    return 0;
}
Пример #2
0
 void handle(event me[2])
 {setviewport(5,5,5+440,5+height,1);
  clearviewport();
  if(is1(flag,0))
  {rad1=pow(m1/500,0.33333333);
   rad2=pow(m2/500,0.33333333);
   //
   if(is1(flag,12))
   {delete tms;
    set0(flag,12);
    if(is1(flag,7))
    {delete array[0];delete array[1];delete array[2];delete array[3];
     set0(flag,7);
    }
    if(is1(flag,6))
    {delete array[0];delete array[1];delete array[2];delete array[3];
     set0(flag,6);
    }
    if(is1(flag,5))
    {delete array[0];delete array[1];delete array[2];delete array[3];
     set0(flag,5);
    }
   }
   //
    if((me[1].b&1)==1)
    {vector vm2(me[2].x-5-220,height/2-me[2].y+5),
	     vm1(me[1].x-5-220,height/2-me[1].y+5);
     if((me[2].b&1)==0)
     { if((r1+v1-vm1).mod()<=5)
       set1(flag,8);
       else if((r2+v2-vm1).mod()<=5)
       set1(flag,9);
       else if((r1-vm1).mod()<=rad1)
       set1(flag,10);
       else if((r2-vm1).mod()<=rad2)
       set1(flag,11);
     }
     else if(me[1].x>5&&me[1].x<445&&me[1].y>5&&me[1].y<(5+height))
     { if(is1(flag,8))
	v1=vm1-r1;
       else if(is1(flag,9))
	v2=vm1-r2;
       else if(is1(flag,10))
	r1=vm1;
       else if(is1(flag,11))
	r2=vm1;
     }
    }
    else
    {set0(flag,8);set0(flag,9);set0(flag,10);set0(flag,11);
    }
    setcolor(COL1);
    setfillstyle(SOLID_FILL,COL1);
    fillellipse(r1.x+220,height/2-r1.y,rad1*10./9,rad1);
    setcolor(14);
    setfillstyle(SOLID_FILL,14);
    fillellipse(r2.x+220,height/2-r2.y,rad2*10./9,rad2);
    //
    setcolor(1);
    line(220+r1.x,height/2-r1.y,220+r1.x+v1.x,height/2-r1.y-v1.y);
    double ang=angle(v1.x,-v1.y);
    int pol[8];
    setfillstyle(SOLID_FILL,1);
    pol[0]=220+r1.x+v1.x;pol[1]=height/2-r1.y-v1.y;
    pol[2]=220+r1.x+v1.x+4*cos(ang+2.5);pol[3]=height/2-r1.y-v1.y+4*sin(ang+2.5);
    pol[4]=220+r1.x+v1.x+4*cos(ang-2.5);pol[5]=height/2-r1.y-v1.y+4*sin(ang-2.5);
    pol[6]=220+r1.x+v1.x;pol[7]=height/2-r1.y-v1.y;
    fillpoly(4,pol);
    //
    setcolor(2);
    line(220+r2.x,height/2-r2.y,220+r2.x+v2.x,height/2-r2.y-v2.y);
    ang=angle(v2.x,-v2.y);
    setfillstyle(SOLID_FILL,2);
    pol[0]=220+r2.x+v2.x;pol[1]=height/2-r2.y-v2.y;
    pol[2]=220+r2.x+v2.x+4*cos(ang+2.5);pol[3]=height/2-r2.y-v2.y+4*sin(ang+2.5);
    pol[4]=220+r2.x+v2.x+4*cos(ang-2.5);pol[5]=height/2-r2.y-v2.y+4*sin(ang-2.5);
    pol[6]=220+r2.x+v2.x;pol[7]=height/2-r2.y-v2.y;
    fillpoly(4,pol);
  }
  if(is1(flag,1))
  {if(is0(flag,12))
   {set1(flag,12);
    tms=new Two_Mass_System(m1,m2,r1,r2,v1,v2);
    if(is1(flag,13))
    {  setviewport(0,0,639,349,1);
       active
       setfillstyle(SOLID_FILL,7);
       bar(0,349-charheight-1,639,349);
       status("Wait...");
       active
       setviewport(5,5,5+440,5+height,1);
     if((tms->s->flag==2||tms->s->flag==3)&&tms->s->T*2/0.05<2000)
     {array[0]=new double[tms->s->T*2/0.05+25];
      array[1]=new double[tms->s->T*2/0.05+25];
      array[2]=new double[tms->s->T*2/0.05+25];
      array[3]=new double[tms->s->T*2/0.05+25];
      long i=0;
      for(double q=0;q<=tms->s->T*2+0.6;q+=0.05,i++)
      {tms->position_wrt_cm(q,w1,w2);
       array[0][i]=w1.x;
       array[1][i]=w1.y;
       array[2][i]=w2.x;
       array[3][i]=w2.y;
      }
      set1(flag,7);
     }
     if(tms->s->flag==1||tms->s->flag==4)
     {array[0]=new double[20/0.05+25];
      array[1]=new double[20/0.05+25];
      array[2]=new double[20/0.05+25];
      array[3]=new double[20/0.05+25];
      long i=0;
      for(double q=0;q<=20+0.5;q+=0.05,i++)
      {tms->position_wrt_cm(q,w1,w2);
       array[0][i]=w1.x;
       array[1][i]=w1.y;
       array[2][i]=w2.x;
       array[3][i]=w2.y;
      }
      set1(flag,6);
     }
     if(tms->s->flag==2&&tms->s->T*2/0.05>=2000)
     {array[0]=new double[40/0.05+25];
      array[1]=new double[40/0.05+25];
      array[2]=new double[40/0.05+25];
      array[3]=new double[40/0.05+25];
      long i=0;
      for(double q=-20-0.5;q<=20+0.5;q+=0.05,i++)
      {tms->position_wrt_cm(q,w1,w2);
       array[0][i]=w1.x;
       array[1][i]=w1.y;
       array[2][i]=w2.x;
       array[3][i]=w2.y;
      }
      set1(flag,5);
     }
    }
    t=0;
   }

   if(is1(flag,7))
   {setcolor(8);
    for(long i=2;i<t/0.05&&i*0.05<=tms->s->T*2+0.5;i++)
    {line(220+array[0][i],height/2-array[1][i]*0.9,220+array[0][i+1],height/2-array[1][i+1]*0.9);
     line(220+array[2][i],height/2-array[3][i]*0.9,220+array[2][i+1],height/2-array[3][i+1]*0.9);
    }
   }
   if(is1(flag,6))
   {setcolor(8);
     for(long i=2;i<t/0.05&&i*0.05<=20;i++)
     {line(220+array[0][i],height/2-array[1][i]*0.9,220+array[0][i+1],height/2-array[1][i+1]*0.9);
      line(220+array[2][i],height/2-array[3][i]*0.9,220+array[2][i+1],height/2-array[3][i+1]*0.9);
     }
   }
   if(is1(flag,5))
   {setcolor(8);
     for(long i=(20+0.5)/0.05;i*0.05-(20+0.5)<t&&i*0.05-(20+0.5)<=20;i++)
     {line(220+array[0][i],height/2-array[1][i]*0.9,220+array[0][i+1],height/2-array[1][i+1]*0.9);
      line(220+array[2][i],height/2-array[3][i]*0.9,220+array[2][i+1],height/2-array[3][i+1]*0.9);
     }
     for(i=0.5/0.05;i*0.05<(20+0.5)+t-tms->s->T*2&&i*0.05<=(20+0.5);i++)
     {line(220+array[0][i],height/2-array[1][i]*0.9,220+array[0][i+1],height/2-array[1][i+1]*0.9);
      line(220+array[2][i],height/2-array[3][i]*0.9,220+array[2][i+1],height/2-array[3][i+1]*0.9);
     }
   }
   if(is1(flag,13))
   { tms->position_wrt_cm(t,d1,d2);
     setviewport(0,0,639,349,1);
     if(tms->s->flag==1)status("Moving in Parabolic path");
     if(tms->s->flag==2)status("Moving in Elliptical path");
     if(tms->s->flag==3)status("Moving in Circular path");
     if(tms->s->flag==4)status("Moving in Hyperbolic path");
     setviewport(5,5,5+440,5+height,1);
   }
   else tms->position(t,d1,d2);
   setcolor(COL1);
   setfillstyle(SOLID_FILL,COL1);
   fillellipse(d1.x+220,height/2-d1.y*0.9,rad1*10./9,rad1);
   setcolor(COL2);
   setfillstyle(SOLID_FILL,COL2);
   fillellipse(d2.x+220,height/2-d2.y*0.9,rad2*10./9,rad2);
   t+=dt;
  }
  if(is1(flag,15))
  {setcolor(15);
   char str[100]="An Application by ";
   char ma[13];
   for(int i=0;i<13;i++)
    ma[i]=char(~st_[i]);
   strcat(str,ma);
   strcat(str," to obserb how a Mass  ");
   outtextxy(5,5, str );
   outtextxy(5,5+charheight+5,    "Body is affected in the Gravitational Feild developed" );
   outtextxy(5,5+2*(charheight+5),"by anoher Mass Body. ( Written in CPP )");
  }
  setviewport(0,0,639,349,1);
  setcolor(8);
  line(445,6,445,5+height);
  line(444,7,444,5+height);
  line(443,8,443,5+height);
  line(6,5+height,445,5+height);
  line(7,5+height-1,445,5+height-1);
  line(8,5+height-2,445,5+height-2);
 }