Exemplo n.º 1
0
void MindMap::createFromXml( Xml xml )
{
	// child elements are MindAreaInfo
	for( Xml xmlChild = xml.getFirstChild( "MindArea" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "MindArea" ) ) {
		// construct MindArea from attributes
		MindAreaInfo *info = new MindAreaInfo;
		mindAreas.add( info );

		info -> createFromXml( xmlChild );

		// get areaId
		String id = info -> getAreaId();
		ASSERTMSG( !id.isEmpty() , "area is not defined: " + xmlChild.serialize() );
		ASSERTMSG( mindAreaMap.get( id ) == NULL , id + ": area duplicate found for id=" + id );

		// add
		mindAreaMap.add( id , info );
	}

	// child elements are MindAreaInfo
	Xml xmlLinks = xml.getFirstChild( "MindLinks" );

	Xml xmlChild;
	if( xmlLinks.exists() )
		xmlChild = xmlLinks.getFirstChild( "MindLink" );
	for( ; xmlChild.exists(); xmlChild = xmlChild.getNextChild( "MindLink" ) ) {
		// construct MindArea from attributes
		MindLinkInfo *info = new MindLinkInfo;
		info -> createFromXml( xmlChild );
		mindLinks.add( info );
	}
}
Exemplo n.º 2
0
void MindMap::createConnectionTypeDefSet( Xml xml ) {
	if( !xml.exists() )
		return;

	for( Xml xmlChild = xml.getFirstChild( "connection-type" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "connection-type" ) ) {
		// construct MindArea from attributes
		MindConnectionTypeDef *linkType = new MindConnectionTypeDef;
		linkType -> createFromXml( xmlChild );
		connectionTypeSet.add( linkType );
		connectionTypeMap.add( linkType -> getName() , linkType );
	}
}
void XmlSpinalCordLayout::load( Xml xmlDiv ) {
	Xml layout = xmlDiv.getFirstChild( "layout" );
	ASSERTMSG( layout.exists() , "layout is not found" );

	imgSrc = layout.getAttribute( "imgsrc" , "" );

	for( Xml xmlChild = layout.getFirstChild( "level" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "level" ) ) {
		String id = xmlChild.getAttribute( "id" );
		MapStringToClass<StringList>& levelData = data.getRef( id );

		loadLevel( xmlChild , levelData );
	}
}
Exemplo n.º 4
0
void MindAreaInfo::createFromXml( Xml xml )
{
	// attributes are properties
	areaId = xml.getAttribute( "id" );

	int x , y , z;
	x = xml.getIntProperty( "posX" );
	y = xml.getIntProperty( "posY" );
	z = xml.getIntProperty( "posZ" );
	location.setPosition( x , y , z );

	int dx , dy , dz;
	dx = xml.getIntProperty( "sizeX" );
	dy = xml.getIntProperty( "sizeY" );
	dz = xml.getIntProperty( "sizeZ" );
	location.setDimensions( dx , dy , dz );

	size = location.getSize();

	// child elements are MindLink
	for( Xml xmlChild = xml.getFirstChild( "MindLink" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "MindLink" ) ) {
		// construct MindArea from attributes
		MindLinkInfo *info = new MindLinkInfo;
		info -> createFromXml( xmlChild );

		// add
		links.add( info );
	}
}
Exemplo n.º 5
0
void XmlBrainTractPath::load( Xml xml ) {
	id = xml.getAttribute( "id" );
	type = xml.getAttribute( "type" );
	function = xml.getAttribute( "function" );
	pathway = xml.getAttribute( "pathway" );

	String src = xml.getAttribute( "src" );
	String dst = xml.getAttribute( "dst" );
	String mids = xml.getAttribute( "mids" , "" );

	items.add( src );
	StringList midlist;
	mids.split( midlist , "," );
	items.add( &midlist );
	items.add( dst );

	tract.addPath( this );

	String fibersvalue = xml.getAttribute( "fibers" );
	fibersvalue.split( fibers , "," );
	String value = xml.getAttribute( "endings" );
	value.split( endings , "," );

	for( Xml xmlChild = xml.getFirstChild( "path" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "path" ) ) {
		XmlBrainTractPath *path = new XmlBrainTractPath( tract , this );
		path -> load( xmlChild );
		childs.add( path -> id , path );
	}
}
Exemplo n.º 6
0
void MindMap::createTargetMeta_defineCircuit( Xml xml , TargetAreaDef *areaDef , bool sensors ) {
	if( sensors )
		areaDef -> defineSensorArea();
	else
		areaDef -> defineEffectorArea();

	mindAreaMap.add( areaDef -> getAreaId() , areaDef );

	// create sensor meta
	String itemsElement = ( sensors )? "sensors" :  "effectors";
	String itemElement = ( sensors )? "sensor" :  "effector";

	Xml config = xml.getChildNode( itemsElement );
	for( Xml xmlChild = config.getFirstChild( itemElement ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( itemElement ) ) {
		TargetRegionDef *regionInfo = new TargetRegionDef( areaDef );

		if( sensors )
			regionInfo -> defineSensorRegion( xmlChild );
		else
			regionInfo -> defineEffectorRegion( xmlChild );

		// add to maps
		areaDef -> addRegion( regionInfo );
		mindRegionMap.add( regionInfo -> getId() , regionInfo );
		TargetRegionTypeDef *regionTypeInfo = ( TargetRegionTypeDef * )regionInfo -> getType();
		regionTypeMap.add( regionTypeInfo -> getName() , regionTypeInfo );

		TargetCircuitDef *circuitInfo = regionTypeInfo -> getCircuitInfo();
		mindCircuitMap.add( circuitInfo -> getName() , circuitInfo );

		regionInfo -> setCircuitDef( circuitInfo );
	}
}
void MindRegionTypeDef::createConnectorSetFromXml( Xml xml ) {
	if( !xml.exists() )
		return;

	for( Xml xmlChild = xml.getFirstChild( "connector" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "connector" ) ) {
		// construct MindArea from attributes
		MindRegionConnectorDef *connector = new MindRegionConnectorDef;
		connector -> createFromXml( xmlChild );

		String id = connector -> getId();
		ASSERTMSG( !id.isEmpty() , "region type connector is not well-defined: " + xmlChild.serialize() );

		// add to set and map
		connectorSet.add( connector );
		connectorMap.add( id , connector );
	}
}
Exemplo n.º 8
0
void MindMap::createCircuitDefSet( Xml xml ) {
	if( !xml.exists() )
		return;

	// check using another file
	EnvService *es = EnvService::getService();
	String xmlFile = xml.getAttribute( "xmlfile" , "" );
	if( !xmlFile.isEmpty() )
		xml = es -> loadXml( xmlFile );

	for( Xml xmlChild = xml.getFirstChild( "circuit" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "circuit" ) ) {
		// construct MindArea from attributes
		MindCircuitDef *circuit = new MindCircuitDef;
		circuit -> createFromXml( xmlChild );
		mindCircuitSet.add( circuit );
		mindCircuitMap.add( circuit -> getName() , circuit );
	}
}
Exemplo n.º 9
0
void AIKnowledgeImpl::createService( Xml config )
{
	// create controllers
	Xml configControllers = config.getFirstChild( "controllers" );
	if( !configControllers.exists() )
		return;

	addKnowledgeController( configControllers , KnowledgeController::createImageKnowledgeBase() );
}
Exemplo n.º 10
0
void MindMap::createRegionTypeDefSet( Xml xml ) {
	if( !xml.exists() )
		return;

	for( Xml xmlChild = xml.getFirstChild( "region-type" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "region-type" ) ) {
		// construct MindRegionType from attributes
		MindRegionTypeDef *info = new MindRegionTypeDef;
		regionTypeSet.add( info );

		info -> createFromXml( xmlChild );

		// get region type name
		String name = info -> getName();
		ASSERTMSG( !name.isEmpty() , "region type is not defined: " + xmlChild.serialize() );
		ASSERTMSG( regionTypeMap.get( name ) == NULL , name + ": region type duplicate found for name=" + name );

		// add
		regionTypeMap.add( name , info );
	}
}
Exemplo n.º 11
0
Xml Xml::findChildByPathAttr( String path , String attr , String value ) {
	Xml xml = findChildByPath( path );
	if( !xml.exists() )
		return( xml );

	String key;
	int index = path.findLast( '/' );
	if( index < 0 )
		key = path;
	else
		key = path.getMid( index + 1 );

	while( xml.exists() ) {
		if( xml.getAttribute( attr , "" ).equals( value ) )
			return( xml );

		xml = xml.getNextChild( key );
	}
	return( xml );
}
void MindRegionTypeDef::createFromXml( Xml xml ) {
	if( !xml.exists() )
		return;

	// attributes
	name = xml.getAttribute( "name" );
	Object::setInstance( name );

	implementation = xml.getAttribute( "implementation" );

	// childs
	createConnectorSetFromXml( xml );
}
Exemplo n.º 13
0
void MindTarget::addSensor( String p_id , MindSensor *sensor ) {
	Xml configSensors = config.getChildNode( "sensors" );
	Xml xconfig = configSensors.findChildByPathAttr( "sensor" , "id" , p_id );

	bool offline = true;
	if( xconfig.exists() && xconfig.getBooleanAttribute( "run" , true ) ) {
		sensor -> configureSensor( xconfig );
		offline = false;
	}

	sensor -> setSensorId( p_id );
	sensorArea -> addSensor( sensor , offline );
}
Exemplo n.º 14
0
void MindMap::createAreaDefSet( Xml xml ) {
	if( !xml.exists() )
		return;

	for( Xml xmlChild = xml.getFirstChild( "area" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "area" ) ) {
		// construct MindArea from attributes
		MindAreaDef *info = new MindAreaDef;
		mindAreaSet.add( info );

		info -> createFromXml( xmlChild );

		// get areaId
		String id = info -> getAreaId();
		ASSERTMSG( !id.isEmpty() , "area is not defined: " + xmlChild.serialize() );
		ASSERTMSG( mindAreaMap.get( id ) == NULL , id + ": area duplicate found for id=" + id );

		// add
		mindAreaMap.add( id , info );

		// add regions to map
		createRegionMap( info );
	}
}
Exemplo n.º 15
0
void MindTarget::addEffector( String p_id , MindEffector *effector ) {
	Xml configEffectors = config.getChildNode( "effectors" );
	Xml xconfig = configEffectors.findChildByPathAttr( "effector" , "id" , p_id );

	ASSERTMSG( xconfig.exists() , "addEffector: unknown target id=" + p_id );

	bool offline = true;
	if( xconfig.getBooleanAttribute( "run" , true ) ) {
		effector -> configureEffector( xconfig );
		offline = false;
	}

	effector -> setEffectorId( p_id );
	effectorArea -> addEffector( effector , offline );
}
void MindConnectionTypeDef::createFromXml( Xml xml ) {
	// attributes
	name = xml.getAttribute( "name" );
	Object::setInstance( name );

	srcRegionType = xml.getAttribute( "regionsrc" );
	dstRegionType = xml.getAttribute( "regiondst" );

	// links
	for( Xml xmlChild = xml.getFirstChild( "link-type" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "link-type" ) ) {
		// construct MindArea from attributes
		MindConnectionLinkTypeDef *link = new MindConnectionLinkTypeDef( this );
		link -> createFromXml( xmlChild );
		links.add( link );
		linkMap.add( link -> getName() , link );
	}
}
void XmlSpinalCordLayout::loadLevel( Xml xmlLevel , MapStringToClass<StringList>& levelData ) {
	for( Xml xmlChild = xmlLevel.getFirstChild( "lamina" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "lamina" ) ) {
		String id = xmlChild.getAttribute( "id" );
		String elements = xmlChild.getAttribute( "elements" );

		StringList& items = levelData.getRef( id );
		StringList parts;
		elements.split( parts , "," );
		for( int k = 0; k < parts.count(); k++ ) {
			String element = parts.get( k );
			ASSERTMSG( hmind -> getIndexedElement( element ) != NULL , "unknown element index=" + element );

			if( items.find( element ) < 0 )
				items.add( element );
		}
	}
}
void MindCircuitDef::createFromXml( Xml xml ) {
	// attributes are properties
	id = xml.getAttribute( "id" );
	name = xml.getAttribute( "name" );
	Object::setInstance( name );

	enabled = xml.getBooleanAttribute( "enabled" , true );
	if( !enabled )
		return;

	// read connections
	for( Xml xmlChild = xml.getFirstChild( "connection" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "connection" ) ) {
		// construct MindArea from attributes
		MindCircuitConnectionDef *connection = new MindCircuitConnectionDef( this );
		connection -> createFromXml( xmlChild );
		connections.add( connection );
	}
}
Exemplo n.º 19
0
void AIKnowledgeImpl::addKnowledgeController( Xml configControllers , KnowledgeController *controller )
{
	String name = controller -> getName();

	// find configuration
	Xml config = configControllers.getChildNamedNode( "controller" , name );
	ASSERTMSG( config.exists() , "Configuration not found for knowledge controller=" + name );

	if( !config.getBooleanAttribute( "run" ) ) {
		// do not use this controller
		delete controller;
		logger.logInfo( "addKnowledgeController: knowledge controller ignored as not configured to run - name=" + name );
		return;
	}

	// add controller
	controllers.add( name , controller );
	controller -> createController( config );
	logger.logInfo( "addKnowledgeController: knowledge controller created - name=" + name );
}
Exemplo n.º 20
0
void MindAreaDef::createFromXml( Xml xml ) {
	// attributes are properties
	areaId = xml.getAttribute( "id" );
	areaType = xml.getAttribute( "type" );
	areaName = xml.getAttribute( "name" );
	areaFunction = xml.getAttribute( "function" );
	Object::setInstance( areaId );

	enabled = xml.getBooleanAttribute( "enabled" , true );
	if( !enabled )
		return;

	// read regions
	for( Xml xmlChild = xml.getFirstChild( "region" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "region" ) ) {
		// construct MindArea from attributes
		MindRegionDef *region = new MindRegionDef( this );
		region -> createFromXml( xmlChild );
		regions.add( region );
		regionMap.add( region -> getId() , region );
	}
}
Exemplo n.º 21
0
void Sensors::addSensor( Xml configSensors , Sensor *att )
{
	String name = att -> getName();
	Xml config = configSensors.getChildNamedNode( "sensor" , name );

	if( config.exists() && config.getBooleanAttribute( "run" ) ) {
		sensors.add( name , att );
		logger.logInfo( "addSensor: sensor added - name=" + name );
	}
	else {
		sensorsOffline.add( name , att );
		logger.logInfo( "addSensor: sensor is not configured to run - name=" + name );
	}

	// generate cortex dimentions - square-like
	BrainLocation cortexLocation;
	int inputsDim1 , inputsDim2;
	int nInputs = att -> getNInputs( inputsDim1 , inputsDim2 );
	int outputsDim1 , outputsDim2;
	int nOutputs = att -> getNOutputs( outputsDim1 , outputsDim2 );

	// two layers: upper - control, lower - sensor data
	int dz = 2;

	// make cortex location
	int dx = max( inputsDim1 , outputsDim1 );
	int dy = max( inputsDim2 , outputsDim2 );

	cortexLocation.setDimensions( dx , dy , dz );
	cortexLocation.setOrientationZ( true );
	BrainLocation areaLocation = MindArea::getLocation();
	areaLocation.placeLocation( coverLocation , cortexLocation );

	// add to brain
	AIBrain brain;
	brain.createSensorCortex( this , cortexLocation , att );
}
Exemplo n.º 22
0
Xml Xml::findChildByPath( String path ) {
	Xml xml = *this;

	const char *p = path;
	while( *p ) {
		const char *np = strchr( p , '/' );

		String key;
		if( np == NULL ) {
			key = p;
			p += strlen( p );
		}
		else {
			key = path.getMid( p - path , np - p );
			p = np + 1;
		}

		xml = xml.getFirstChild( key );
		if( !xml.exists() )
			return( xml );
	}

	return( xml );
}
Exemplo n.º 23
0
void ScenarioPlayer::play( Xml scenario ) {
    logger.logInfo( "process scenario ..." );
    for( Xml xmlChild = scenario.getFirstChild( "xmlsignal" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "xmlsignal" ) )
        playSignal( xmlChild );
}