<commit_before>// Copyright (c) The University of Cincinnati.  
// All rights reserved.

// UC MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF 
// THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  UC SHALL NOT BE LIABLE
// FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
// RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
// DERIVATIVES.
// By using or copying this Software, Licensee agrees to abide by the
// intellectual property laws, and all other applicable laws of the
// U.S., and the terms of this license.

#include "EpidemicApplication.h"
#include "LocationObject.h"
#include "EpidemicPartitioner.h"
#include "Person.h"
#include <warped/PartitionInfo.h>
#include <warped/DeserializerManager.h>
#include <utils/ArgumentParser.h>

#include <vector>
#include <iostream>
#include <fstream>

using namespace std;


EpidemicApplication::EpidemicApplication(): inputFileName( "" ), numObjects( 0 ) { }

int EpidemicApplication::initialize( vector<string> &arguments ){

	getArgumentParser().checkArgs( arguments );

	if( inputFileName.empty() ) {
		cerr << "A epidemicSim configuration file must be specified using -simulate" << endl;
		abort();
	}
	return 0;
}

int EpidemicApplication::getNumberOfSimulationObjects(int mgrId) const {
	return numObjects;
}

const PartitionInfo *EpidemicApplication::getPartitionInfo(
					unsigned int numberOfProcessorsAvailable ) {

	EpidemicPartitioner *myPartitioner = new EpidemicPartitioner();
	int numRegions = 0, numLocations = 0, numPersons = 0;
	unsigned int pid = 0;
	float susceptibility = 0.0, transmissibility = 0.0;
	string locationName = "", infectionState = "";

	Person *person;
	vector <SimulationObject*> *locObjs;
	vector <Person *> *personVec;

	ifstream configFile;
	configFile.open( inputFileName.c_str() );
	if(configFile.fail()) {
		cerr << "Could not open file: '" << inputFileName << "'" << endl;
		cerr << "Terminating simulation." << endl;
		abort();
	}
	configFile >> transmissibility >> numRegions;

	/* If needed (to limit the LPs of a region to a specific processor */
	//if(numRegions > numberOfProcessorsAvailable) {
	//	cerr << "Not enough processors alotted for all the regions." << endl;
	//	abort();
	//}

	/* For each region in the simulation, initialize the locations */
	for( int regIndex = 0; regIndex < numRegions; regIndex++ ) {

		locObjs = new vector<SimulationObject*>;  
		numLocations = 0;
		configFile >> numLocations;

		for( int locIndex = 0; locIndex < numLocations; locIndex++ ) {

			personVec = new vector <Person *>;

			configFile >> locationName >> numPersons;

			/* Read each person's details */
			for(int perIndex = 0; perIndex < numPersons; perIndex++) {

				configFile >> pid >> susceptibility >> infectionState;
				person = new Person( pid, susceptibility, infectionState );
				personVec->push_back( person );
			}

			LocationObject *locObject = new LocationObject( locationName,
															transmissibility,
															personVec);
			locObjs->push_back(locObject);
		}
		numObjects += numLocations;

		/* Add the group of objects to the partition information */
		myPartitioner->addObjectGroup(locObjs);
	}

	/* Perform the actual partitioning of groups */
	const PartitionInfo *retval = myPartitioner->partition( NULL, numberOfProcessorsAvailable );

	configFile.close();
	return retval;
}

int EpidemicApplication::finalize() {
	return 0;
}

void EpidemicApplication::registerDeserializers() {
}

ArgumentParser & EpidemicApplication::getArgumentParser() {

	static ArgumentParser::ArgRecord args[] = {
		{ "-simulate", "input file name", &inputFileName, ArgumentParser::STRING, false },
		{ "", "", 0 }
	};

	static ArgumentParser *myArgParser = new ArgumentParser( args );
	return *myArgParser;
}
<commit_msg>register serializer method def added<commit_after>// Copyright (c) The University of Cincinnati.  
// All rights reserved.

// UC MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF 
// THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  UC SHALL NOT BE LIABLE
// FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
// RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
// DERIVATIVES.
// By using or copying this Software, Licensee agrees to abide by the
// intellectual property laws, and all other applicable laws of the
// U.S., and the terms of this license.

#include "EpidemicApplication.h"
#include "LocationObject.h"
#include "EpidemicPartitioner.h"
#include "Person.h"
#include <warped/PartitionInfo.h>
#include <warped/DeserializerManager.h>
#include <utils/ArgumentParser.h>

#include <vector>
#include <iostream>
#include <fstream>

using namespace std;


EpidemicApplication::EpidemicApplication(): inputFileName( "" ), numObjects( 0 ) { }

int EpidemicApplication::initialize( vector<string> &arguments ){

	getArgumentParser().checkArgs( arguments );

	if( inputFileName.empty() ) {
		cerr << "A epidemicSim configuration file must be specified using -simulate" << endl;
		abort();
	}
	return 0;
}

int EpidemicApplication::getNumberOfSimulationObjects(int mgrId) const {
	return numObjects;
}

const PartitionInfo *EpidemicApplication::getPartitionInfo(
					unsigned int numberOfProcessorsAvailable ) {

	EpidemicPartitioner *myPartitioner = new EpidemicPartitioner();
	int numRegions = 0, numLocations = 0, numPersons = 0;
	unsigned int pid = 0;
	float susceptibility = 0.0, transmissibility = 0.0;
	string locationName = "", infectionState = "";

	Person *person;
	vector <SimulationObject*> *locObjs;
	vector <Person *> *personVec;

	ifstream configFile;
	configFile.open( inputFileName.c_str() );
	if(configFile.fail()) {
		cerr << "Could not open file: '" << inputFileName << "'" << endl;
		cerr << "Terminating simulation." << endl;
		abort();
	}
	configFile >> transmissibility >> numRegions;

	/* If needed (to limit the LPs of a region to a specific processor */
	//if(numRegions > numberOfProcessorsAvailable) {
	//	cerr << "Not enough processors alotted for all the regions." << endl;
	//	abort();
	//}

	/* For each region in the simulation, initialize the locations */
	for( int regIndex = 0; regIndex < numRegions; regIndex++ ) {

		locObjs = new vector<SimulationObject*>;  
		numLocations = 0;
		configFile >> numLocations;

		for( int locIndex = 0; locIndex < numLocations; locIndex++ ) {

			personVec = new vector <Person *>;

			configFile >> locationName >> numPersons;

			/* Read each person's details */
			for(int perIndex = 0; perIndex < numPersons; perIndex++) {

				configFile >> pid >> susceptibility >> infectionState;
				person = new Person( pid, susceptibility, infectionState );
				personVec->push_back( person );
			}

			LocationObject *locObject = new LocationObject( locationName,
															transmissibility,
															personVec);
			locObjs->push_back(locObject);
		}
		numObjects += numLocations;

		/* Add the group of objects to the partition information */
		myPartitioner->addObjectGroup(locObjs);
	}

	/* Perform the actual partitioning of groups */
	const PartitionInfo *retval = myPartitioner->partition( NULL, numberOfProcessorsAvailable );

	configFile.close();
	return retval;
}

int EpidemicApplication::finalize() {
	return 0;
}

void EpidemicApplication::registerDeserializers() {
	DeserializerManager::instance()->registerDeserializer(  EpidemicEvent::getEpidemicEventDataType(), 
															&EpidemicEvent::deserialize );
}

ArgumentParser & EpidemicApplication::getArgumentParser() {

	static ArgumentParser::ArgRecord args[] = {
		{ "-simulate", "input file name", &inputFileName, ArgumentParser::STRING, false },
		{ "", "", 0 }
	};

	static ArgumentParser *myArgParser = new ArgumentParser( args );
	return *myArgParser;
}

{'fraction_non_alphanumeric': 0.11276969392875062, 'fraction_numerical': 0.004014049172102358, 'mean_word_length': 4.401761517615176, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2400460', 'n_tokens_mistral': 2580, 'n_tokens_neox': 2314, 'n_words': 723}