Пример #1
0
bool Utils::copyOneFile(const QString& src, const QString& dst)
{
    QFile sFile(src);
    QFile dFile(dst);

    if ( !sFile.open(QIODevice::ReadOnly) )
        return false;

    if ( !dFile.open(QIODevice::WriteOnly) )
    {
        sFile.close();
        return false;
    }

    const int MAX_IPC_SIZE = (1024*32);
    char buffer[MAX_IPC_SIZE];

    qint64 len;
    while ((len = sFile.read(buffer, MAX_IPC_SIZE)) != 0)
    {
        if (len == -1 || dFile.write(buffer, (qint64)len) == -1)
        {
            sFile.close();
            dFile.close();
            return false;
        }
    }

    sFile.close();
    dFile.close();

    return true;
}
Пример #2
0
GpgME::VerificationResult SignaturePrivate::verify(const KUrl &dest, const QByteArray &sig)
{
    GpgME::VerificationResult result;
    if (!QFile::exists(dest.pathOrUrl()) || sig.isEmpty()) {
        return result;
    }

    GpgME::initializeLibrary();
    GpgME::Error error = GpgME::checkEngine(GpgME::OpenPGP);
    if (error) {
        kDebug(5001) << "OpenPGP not supported!";
        return result;
    }

    QScopedPointer<GpgME::Context> context(GpgME::Context::createForProtocol(GpgME::OpenPGP));
    if (!context.data()) {
        kDebug(5001) << "Could not create context.";
        return result;
    }

    boost::shared_ptr<QFile> qFile(new QFile(dest.pathOrUrl()));
    qFile->open(QIODevice::ReadOnly);
    QGpgME::QIODeviceDataProvider *file = new QGpgME::QIODeviceDataProvider(qFile);
    GpgME::Data dFile(file);

    QGpgME::QByteArrayDataProvider signatureBA(sig);
    GpgME::Data signature(&signatureBA);

    return context->verifyDetachedSignature(signature, dFile);
}
Пример #3
0
int DataFileManager::openFile(const Datum &oeDatum) {
    std::string dFile(oeDatum.getElement(DATA_FILE_FILENAME).getString());
    DatumFileOptions opt = (DatumFileOptions)oeDatum.getElement(DATA_FILE_OPTIONS).getInteger();
    
    if(dFile.size() == 0) {
        merror(M_FILE_MESSAGE_DOMAIN, "Attempt to open data file with an empty name");
        return -1;
    }
    
    return openFile(dFile, opt);
}
Пример #4
0
int DataFileManager::openFile(const Datum &oeDatum) {
	std::string dFile(oeDatum.getElement(DATA_FILE_FILENAME).getString());
 DatumFileOptions opt = (DatumFileOptions)oeDatum.getElement(DATA_FILE_OPTIONS).getInteger();
	
	if(dFile.size() == 0) {
		merror(M_FILE_MESSAGE_DOMAIN, 
			   "Attempt to open an empty data file");
		return -1;
	}
	if(GlobalDataFileManager->isFileOpen()) {
		mwarning(M_FILE_MESSAGE_DOMAIN,
				 "Data file already open at %s", 
				 (GlobalDataFileManager->getFilename()).c_str());
		return -1;
	}
	
	return openFile(dFile, opt);
}
int main(int argc, char* argv[]) {
    int run_num = 0; 
    run_num = atoi(argv[1]); //read in the run number of this simulation

    int seed = 0;
    seed = atoi(argv[2]); //read in the seed for the random number generator of this simulation
	srand(seed);

    int arg = 0;

    int typeTest = 0;
    typeTest = atoi(argv[3]); //read the type of test this simulation is doing

    int tempTTTindex = 0;
    int temphysindex = 0;

    std::string folder = "";
    //case statement of the different simulation type with TTT and hys values
    //as well as the folder to output to
    switch(typeTest) {
        case 0:
            folder = "high";
            tempTTTindex = 15;
            temphysindex = 20;
            arg = 3;
            break;
        case 1:
            folder = "highhys";
            tempTTTindex = 3;
            temphysindex = 15;
            arg = 3;
            break;
        case 2:
            folder = "low";
            tempTTTindex = 0;
            temphysindex = 0;
            arg = 3;
            break;
        case 3:
            folder = "mid";
            tempTTTindex = 7;
            temphysindex = 10;
            arg = 3;
            break;
        case 4:
            folder = "opthigh";
            tempTTTindex = 15;
            temphysindex = 20;
            arg = 2;
            break;
        case 5:
            folder = "opthighhys";
            tempTTTindex = 3;
            temphysindex = 15;
            arg = 2;
            break;
        case 6:
            folder = "optlow";
            tempTTTindex = 0;
            temphysindex = 0;
            arg = 2;
            break;
        case 7:
            folder = "optmid";
            tempTTTindex = 7;
            temphysindex = 10;
            arg = 2;
            break;
        default:
            // program should not reach here
            break;
    }

	//set the TTTindex array to the correct values
    for(int j=0; j<NUM_BASESTATION; j++) {
        TTTindex[j] = tempTTTindex;
    }
    //set the hysindex array to the correct values
    for(int k=0; k<NUM_BASESTATION; k++) {
        hysindex[k] = temphysindex;
    }

	TTTmaxindex = 15;
	hysmaxindex = 20;

	TTTArray[0] = 0.0;
	TTTArray[1] = 0.04;
	TTTArray[2] = 0.064;
	TTTArray[3] = 0.08;
	TTTArray[4] = 0.1;
	TTTArray[5] = 0.128;
	TTTArray[6] = 0.16;
	TTTArray[7] = 0.256;
	TTTArray[8] = 0.32;
	TTTArray[9] = 0.48;
	TTTArray[10] = 0.512;
	TTTArray[11] = 0.64;
	TTTArray[12] = 1.024;
	TTTArray[13] = 1.280;
	TTTArray[14] = 2.56;
	TTTArray[15] = 5.12;

	hysArray[0] = 0.0;
	hysArray[1] = 0.5;
	hysArray[2] = 1.0;
	hysArray[3] = 1.5;
	hysArray[4] = 2.0;
	hysArray[5] = 2.5;
	hysArray[6] = 3.0;
	hysArray[7] = 3.5;
	hysArray[8] = 4.0;
	hysArray[9] = 4.5;
	hysArray[10] = 5.0;
	hysArray[11] = 5.5;
	hysArray[12] = 6.0;
	hysArray[13] = 6.5;
	hysArray[14] = 7.0;
	hysArray[15] = 7.5;
	hysArray[16] = 8.0;
	hysArray[17] = 8.5;
	hysArray[18] = 9.0;
	hysArray[19] = 9.5;
	hysArray[20] = 10.0;

	//set the TTT and hys arrays to the correct values
	for(int i=0; i<NUM_BASESTATION; i++) {
		TTT[i] = TTTArray[TTTindex[i]];
		hys[i] = hysArray[hysindex[i]];
	}

	// std::cout << "Enter what operation you would like to undertake.\n";
	// std::cout << "1 for generating / updating policy\n";
	// std::cout << "2 for using the policy\n";
	// std::cout << "3 for no learning\n";
	// std:: cout << "Please enter:\n";
    //
	// int arg;
	// std::cin >> arg;

	//this block set the function variable.
	//if all the code is commented in and the code above commented out then
	//the simulation can be run with user given parameters instead of parameters
	//given by the bash script.
	if(arg == 1) {
		// q-learning
		printf("Q-Learning started...\n");
		function = 1;
	} else if(arg == 2) {
		// use policy
		printf("Simulation started...\n");
        // printf("Enter index for TTT\n");
        // int tempTTTindex;
        // // std::cin >> tempTTTindex;
        // tempTTTindex = atoi(argv[4]);
        // for(int j=0; j<NUM_BASESTATION; j++) {
        //     TTT[j] = TTTArray[tempTTTindex];
        //     TTTindex[j] = tempTTTindex;
        // }
        // // printf("Enter index for hys\n");
        // int temphysindex;
        // // std::cin >> temphysindex;
        // temphysindex = atoi(argv[5]);
        // for(int k=0; k<NUM_BASESTATION; k++) {
        //     hys[k] = hysArray[temphysindex];
        //     hysindex[k] = temphysindex;
        // }
		function = 2;
	}  else if(arg == 3) {
		printf("No learning simulation...\n");
		// printf("Enter index for TTT\n");
		// int tempTTTindex;
		// // std::cin >> tempTTTindex;
        // tempTTTindex = atoi(argv[4]);
		// for(int j=0; j<NUM_BASESTATION; j++) {
		// 	TTT[j] = TTTArray[tempTTTindex];
		// 	TTTindex[j] = tempTTTindex;
		// }
		// // printf("Enter index for hys\n");
		// int temphysindex;
		// // std::cin >> temphysindex;
        // temphysindex = atoi(argv[5]);
		// for(int k=0; k<NUM_BASESTATION; k++) {
		// 	hys[k] = hysArray[temphysindex];
		// 	hysindex[k] = temphysindex;
		// }
		function = 4;
	}

	//instantiate the q-learning agents for the base stations
	q[0] = new q_learning(gs,0,TTTindex[0],hysindex[0]);
	q[1] = new q_learning(gs,1,TTTindex[1],hysindex[1]);
	q[2] = new q_learning(gs,2,TTTindex[2],hysindex[2]);
	q[3] = new q_learning(gs,3,TTTindex[3],hysindex[3]);
	q[4] = new q_learning(gs,4,TTTindex[4],hysindex[4]);
	q[5] = new q_learning(gs,5,TTTindex[5],hysindex[5]);
	q[6] = new q_learning(gs,6,TTTindex[6],hysindex[6]);
	q[7] = new q_learning(gs,7,TTTindex[7],hysindex[7]);
	q[8] = new q_learning(gs,8,TTTindex[8],hysindex[8]);

	gs->start(); //start the scheduler

	//this is where the simulation returns to when the schedulers is stopped by a mobile
	//print the results for the base stations on screen and save the q-vaules and policy
	//for the q-learning agents to external files
	for (int l=0; l<NUM_BASESTATION; l++)
	{
		bStations[l]->print();
		q[l]->saveQValues();
	}

	//This block of code writes the results out to text files in folders
	for(int m=0; m<NUM_BASESTATION; m++) {
		std::stringstream hString;
		hString << "results/longer/" << folder << run_num << "/basestation" << m << "/handover.txt";
		handoverString = hString.str();

		std::stringstream dString;
		dString<< "results/longer/" << folder << run_num << "/basestation" << m << "/drop.txt";
		dropString = dString.str();

		std::stringstream pString;
		pString << "results/longer/" << folder << run_num << "/basestation" << m << "/ping.txt";
		pingString = pString.str();

        std::stringstream fString;
        fString << "results/longer/" << folder << run_num << "/basestation" << m << "/failure.txt";
        failureString = fString.str();

		std::stringstream sString;
		sString << "results/longer/" << folder << run_num << "/basestation" << m << "/state.txt";
		stateString = sString.str();



		std::ofstream hFile (handoverString);
		if(hFile.is_open()) {
			for (std::vector<double>::iterator it=handover_total[m].begin() ; it!=handover_total[m].end(); it++) {
    		    hFile << *it << "\n";
    		}
    	}
    	hFile.close();

    	std::ofstream dFile (dropString);
		if(dFile.is_open()) {
			for (std::vector<double>::iterator it=drop_total[m].begin() ; it!=drop_total[m].end(); it++) {
    		    dFile << *it << "\n";
    		}
    	}
    	dFile.close();

    	std::ofstream pFile (pingString);
		if(pFile.is_open()) {
			for (std::vector<double>::iterator it=pingpong_total[m].begin() ; it!=pingpong_total[m].end(); it++) {
    		    pFile << *it << "\n";
    		}
    	}
    	pFile.close();

        std::ofstream fFile (failureString);
        if(fFile.is_open()) {
            for (std::vector<double>::iterator it=failure_total[m].begin() ; it!=failure_total[m].end(); it++) {
                fFile << *it << "\n";
            }
        }
        fFile.close();

    	std::ofstream sFile (stateString);
		if(sFile.is_open()) {
			for (std::vector<int>::iterator it=stateChanges[m].begin() ; it!=stateChanges[m].end(); it++) {
    		    sFile << *it << "\n";
    		}
    	}
    	sFile.close();
    }

	printf("end...\n");

	delete gs; //delete the scheduler to clean up

	return 0;
}