Exemplo n.º 1
0
/* PerformMgeAdapt: MGE adaptation main procedure */
static void PerformMgeAdapt()
{
   int nIter, nSent;

   /* create data file list */
   CreateDataFileList();
   nSent = g_nDataFileNum;
   nSamples = 0;

   /* synchronize parameters with previous iterations */
   if (nBAEndIter < 0)
      nBAEndIter = endIter;
   for (nIter = 1; nIter < startIter; nIter++) {
      nSamples += nSent;
      ShuffleDataFileList();
      if (nMaxBAIter > 1 && nIter > 0)
         nMaxBAIter -= 1;
      if (nMaxBALen > 1 && nIter > 0)
         nMaxBALen -= 1;
   }
   /* initialize step size */
   mtInfo->initStepSize = 1 / A_STEP;

   /* iteration from startIter to endIter */
   for (nIter = startIter; nIter <= endIter; nIter++) {
      /* shuffle data file list */
      if (nIter != 0)
         ShuffleDataFileList();

      if (trace & T_TOP) {
         fprintf(stdout, "\n\n\n--------------------- Iteration %d -------------------\n", nIter);
         fflush(stdout);
      }
      /* set the flag for boundary adjustment */
      if (nMaxBAIter > 1 || nIter <= nBAEndIter)
         bBoundAdj = mtInfo->bBoundAdj;
      else
         bBoundAdj = FALSE;

      /* one iteration of MGE training */
      nSent = OneIterMgeAdapt(nIter);

      /* print the statistical information of training */
      PrintStatInfo(nSent, nIter);

      /* output intermedia HMM files */
      if (nIter > 0 && outProcData && bMgeUpdate)
         OutputIntmdXForm(nIter);
      /* reduce the shift length after each iteration until it reach to 2 */
      /* heuristic code to improve the efficiency */
      if (nMaxBAIter > 1 && nIter > 0)
         nMaxBAIter -= 1;
      if (nMaxBALen > 1 && nIter > 0)
         nMaxBALen -= 1;
   }

   PrintFinalResult(nSent, nIter);
}
Exemplo n.º 2
0
/* MGE evaluation main procedure */
static void PerformMgeEval()
{
   int nIter, nSent;

   /* create data file list */
   CreateDataFileList();
   nSent = g_nDataFileNum;
   nSamples = 0;

   /* synchronize parameters with previous iterations */
   if (nBAEndIter < 0)
      nBAEndIter = endIter;
   for (nIter = 1; nIter < startIter; nIter++) {
      nSamples += nSent;
      if (nMaxBAIter > 1 && nIter > 0)
         nMaxBAIter -= 1;
      if (nMaxBALen > 1 && nIter > 0)
         nMaxBALen -= 1;
   }

   /* apply transform to related models */
   if (hset.curXForm != NULL)
      ApplyHMMSetXForm(&hset, hset.curXForm, FALSE);

   /* iteration from startIter to endIter */
   for (nIter = startIter; nIter <= endIter; nIter++) {
      if (trace & T_TOP) {
         fprintf(stdout, "\n\n\n--------------------- Iteration %d -------------------\n", nIter);
         fflush(stdout);
      }
      /* load MGE-trained HMM files */
      if (nIter > 0)
         LoadMgeTrnHmmFile(nIter);
      /* set the flag for boundary adjustment */
      bBoundAdj = mtInfo->bBoundAdj;

      /* one iteration of MGE training */
      nSent = OneIterMgeEval(nIter);
      /* print the statistical information of training */
      PrintStatInfo(nSent, nIter);
      /* reduce the shift iterations and length after each iteration until it reach to 1 */
      /* heuristic code to improve the efficiency */
      if (nMaxBAIter > 1 && nIter > 0)
         nMaxBAIter -= 1;
      if (nMaxBALen > 1 && nIter > 0)
         nMaxBALen -= 1;
   }

   PrintFinalResult(nSent, nIter);
}
void Phase_3()
{
    int iUDPBidd1 = 4933, iUDPBidd2 = 5033;
    int iTCPBidd1 = 3933, iTCPBidd2 = 4033;
    int iTCPSell1 =2933 , iTCPSell2 = 3033;
    
    int iUDPSock1, iUDPSock2;
    int iTCPSockB1, iTCPSockB2, iTCPSockS1, iTCPSockS2;
    
    struct sockaddr_in addrServ, addrBidd1, addrBidd2, addrSell1, addrSell2;
    socklen_t addlen = sizeof(addrBidd2);
    
    char buffTx[1024], buffRx1[1024], buffRx2[1024];        
    
    iUDPSock1 = socket(AF_INET, SOCK_DGRAM, 0);
    iUDPSock2 = socket(AF_INET, SOCK_DGRAM, 0);
    
    memset(&addrServ, 0, sizeof(addrServ));
    addrServ.sin_family = AF_INET;
    addrServ.sin_port = htons(0);
    addrServ.sin_addr.s_addr = inet_addr("127.0.0.1");
    int i;
    
    if(bind(iUDPSock1, (struct sockaddr *) &addrServ, sizeof(addrServ)) != 0)
    {
        perror("\nPhase 3: Bind Error ");
    }
    
    if(bind(iUDPSock2, (struct sockaddr *) &addrServ, sizeof(addrServ)) != 0)
    {
        perror("\nPhase 3: Bind Error ");
    }
    
    char szAucIP[20];
    int iCh;
    int iBuffRx, iBuffTx;
    
    void *pAddr;
    struct sockaddr_in *pIP = (struct sockaddr_in *) &addrServ;
        
    pAddr = &pIP->sin_addr;
    inet_ntop(addrServ.sin_family, pAddr, szAucIP, sizeof(szAucIP));
    
    iCh = getsockname(iUDPSock1, (struct sockaddr *) &addrServ, &addlen);
    printf("\nPhase 3: Auction Server has IP address: %s  Auction UDP Port Number: %d", szAucIP, ntohs(addrServ.sin_port));
    iCh = getsockname(iUDPSock2, (struct sockaddr *) &addrServ, &addlen);
    printf("\nPhase 3: Auction Server has IP address: %s  Auction UDP Port Number: %d", szAucIP, ntohs(addrServ.sin_port));
    
    memset(&addrBidd1, 0, sizeof(addrBidd1));
    addrBidd1.sin_family = AF_INET;
    addrBidd1.sin_port = htons(iUDPBidd1);    
    addrBidd1.sin_addr.s_addr = INADDR_ANY;
    
    memset(&addrBidd2, 0, sizeof(addrBidd2));
    addrBidd2.sin_family = AF_INET;
    addrBidd2.sin_port = htons(iUDPBidd2);
    addrBidd2.sin_addr.s_addr = inet_addr("127.0.0.1");//INADDR_ANY;        
    
    memset(&blist, 0, sizeof(blist));
    
    ReadBroadcastList("broadcastList.txt", buffTx);
    
    //Send Broadcast List
    iBuffTx = sendto(iUDPSock1, buffTx, sizeof(buffTx), 0, (struct sockaddr *) &addrBidd1, addlen);
    iBuffTx = sendto(iUDPSock2, buffTx, sizeof(buffTx), 0, (struct sockaddr *) &addrBidd2, addlen);    
    
    memset(&bidd1List, 0 ,sizeof(bidd1List));
    memset(&bidd2List, 0 ,sizeof(bidd2List));
    
    //if(fork() == 0)
    {
        iBuffRx = recvfrom(iUDPSock1, buffRx1, 1024, 0, (struct sockaddr *) &addrBidd1, &addlen);        
        buffRx1[iBuffRx] = '\0';
        RecieveBiddingList(buffRx1, &bidd1List);    
    }    
        
    //if(fork() == 0)
    {
        iBuffRx = recvfrom(iUDPSock2, buffRx2, 1024, 0, (struct sockaddr *) &addrBidd2, &addlen);        
        buffRx2[iBuffRx] = '\0';
        RecieveBiddingList(buffRx2, &bidd2List);        
    }    
                
    close(iUDPSock1);
    close(iUDPSock2);
    
    //Perform Auctioning
    Auction(blist, bidd1List, bidd2List);        
    
    sleep(5);
    
    PrintFinalResult();
    
    //For Bidder 1
    PostResult_Bidd1();
    //For Bidder 2
    PostResult_Bidd2();
    //For Seller 1
    PostResult_Sell1();
    //For Seller 2
    PostResult_Sell2();
}