コード例 #1
0
        public static void Write(EnvConfig envConfig, string xmlFilename)
        {
            // Create new XML document
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode     node;

            // Create "EnvConfig" node
            XmlNode configNode = xmlDoc.CreateElement("EnvConfig");

            xmlDoc.AppendChild(configNode);

            // Populate "GridMath" node
            node = xmlDoc.CreateElement("GridMath");
            configNode.AppendChild(node);
            AddAttribute(xmlDoc, node, "gridOrigin_x", envConfig.gridOrigin_x.ToString());
            AddAttribute(xmlDoc, node, "gridOrigin_z", envConfig.gridOrigin_z.ToString());
            AddAttribute(xmlDoc, node, "gridToWorldScale", envConfig.gridToWorldScale.ToString());

            // Populate "Road" node
            node = xmlDoc.CreateElement("Road");
            configNode.AppendChild(node);
            AddChildCells(xmlDoc, node, envConfig.roadCells);

            // Populate "Mountain" node
            node = xmlDoc.CreateElement("Mountain");
            configNode.AppendChild(node);
            AddChildCells(xmlDoc, node, envConfig.mountainCells);

            // Populate "Water" node
            node = xmlDoc.CreateElement("Water");
            configNode.AppendChild(node);
            AddChildCells(xmlDoc, node, envConfig.waterCells);

            // Populate "Land" node
            node = xmlDoc.CreateElement("Land");
            configNode.AppendChild(node);
            AddChildCells(xmlDoc, node, envConfig.landCells);

            // Write to file
            xmlDoc.Save(xmlFilename);
        }
コード例 #2
0
        public MCTrialGenerator()
        {
            // Read in envConfig
            envConfig = EnvConfigXMLReader.Parse(envConfigFile);
            if (envConfig == null)
            {
                Log.debug("MCTrialGenerator::Main(): Parsed envConfig is null, exiting");
                return;
            }

            // Initialize GridMath object
            gridMath = new GridMath(envConfig.gridOrigin_x, envConfig.gridOrigin_z, envConfig.gridToWorldScale);

            // Populate hashsets of cells for easy lookup
            landCells         = new HashSet <PrimitivePair <int, int> >(envConfig.landCells);
            landAndWaterCells = new HashSet <PrimitivePair <int, int> >(envConfig.landCells);
            landAndWaterCells.UnionWith(envConfig.waterCells);

            // Random generator for determining whether a unit has weapons or jammers etc.
            rand = new Random(generatorRandomSeed);
        }
コード例 #3
0
 private static void ParseGridMath(XmlNode node, EnvConfig envConfig)
 {
     envConfig.gridOrigin_x     = GetFloatAttribute(node, "gridOrigin_x", 0.0f);
     envConfig.gridOrigin_z     = GetFloatAttribute(node, "gridOrigin_z", 0.0f);
     envConfig.gridToWorldScale = GetFloatAttribute(node, "gridToWorldScale", 0.0f);
 }
コード例 #4
0
        public static EnvConfig Parse(string xmlFilename)
        {
            // Initialize EnvConfig object to hold results
            EnvConfig envConfig = new EnvConfig();

            // Read in the XML document
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(xmlFilename);
            }
            catch (System.IO.FileNotFoundException)
            {
                // Handle error if not found
                Log.error("EnvConfigXMLReader::Parse(): Could not load " + xmlFilename);
                return(null);
            }

            // Find the "EnvConfig" category
            XmlNode configNode = null;

            foreach (XmlNode c in xmlDoc.ChildNodes)
            {
                if (c.Name == "EnvConfig")
                {
                    configNode = c;
                    break;
                }
            }

            // Check if we actually found it
            if (configNode == null)
            {
                // Handle error if not found
                Log.error("EnvConfigXMLReader::Parse(): Could not find \"EnvConfig\" node");

                return(null);
            }

            // Parse child nodes
            foreach (XmlNode c in configNode.ChildNodes)
            {
                // Parse differently depending on which category we are in
                switch (c.Name)
                {
                case "GridMath":
                    // Grid math cells
                    ParseGridMath(c, envConfig);
                    break;

                case "Road":
                    // Road cells
                    ParseCells(c, envConfig.roadCells);
                    break;

                case "Mountain":
                    // Mountain cells
                    ParseCells(c, envConfig.mountainCells);
                    break;

                case "Water":
                    // Water cells
                    ParseCells(c, envConfig.waterCells);
                    break;

                case "Land":
                    // Land cells
                    ParseCells(c, envConfig.landCells);
                    break;

                default:
                    // Unrecognized
                    Log.debug("EnvConfigXMLReader::Parse(): Unrecognized node type " + c.Name);
                    break;
                }
            }

            // Return result
            return(envConfig);
        }
コード例 #5
0
ファイル: MCTrialGenerator.cs プロジェクト: mhaque3/soa_unity
        public MCTrialGenerator()
        {
            // Read in envConfig
            envConfig = EnvConfigXMLReader.Parse(envConfigFile);
            if (envConfig == null)
            {
                Log.debug("MCTrialGenerator::Main(): Parsed envConfig is null, exiting");
                return;
            }

            // Initialize GridMath object
            gridMath = new GridMath(envConfig.gridOrigin_x, envConfig.gridOrigin_z, envConfig.gridToWorldScale);

            // Populate hashsets of cells for easy lookup
            landCells         = new HashSet <PrimitivePair <int, int> >(envConfig.landCells);
            landAndWaterCells = new HashSet <PrimitivePair <int, int> >(envConfig.landCells);
            landAndWaterCells.UnionWith(envConfig.waterCells);

            // Random generator for determining whether a unit has weapons or jammers etc.
            rand = new Random(generatorRandomSeed);

            // Type of experiment that will be run
            switch (experimentType)
            {
            case ExperimentType.COMMS_RANGE:
                experiment = new CommsRangeExperiment(this);
                break;

            case ExperimentType.BLUE_NUM:
                experiment = new SmallUAVNumberExperiment(this);
                break;

            case ExperimentType.RED_NUM:
                experiment = new RedAgentNumberExperiment(this);
                break;

            case ExperimentType.RED_PRED:
                experiment = new RedMovePredExperiment(this);
                break;

            case ExperimentType.FACTORIAL:
                experiment = new FactorialExperiment(this);
                break;
            }

            // Blue Base
            blueBases = new List <SiteConfig>();
            blueBases.Add(new BlueBaseConfig(-3.02830208f, -9.7492255f, "Blue Base", new Optional <float>()));

            // Red Base
            redBases = new List <SiteConfig>();
            redBases.Add(new RedBaseConfig(-17.7515077f, 13.7463599f, "Red Base 0"));
            redBases.Add(new RedBaseConfig(-0.439941213f, 12.7518844f, "Red Base 1"));
            redBases.Add(new RedBaseConfig(22.0787984f, 10.7493104f, "Red Base 2"));

            // NGO Site
            ngoSites = new List <SiteConfig>();
            ngoSites.Add(new NGOSiteConfig(-21.2181483f, -1.25010618f, "NGO Site 0"));
            ngoSites.Add(new NGOSiteConfig(-4.76803318f, -5.74888572f, "NGO Site 1"));
            ngoSites.Add(new NGOSiteConfig(11.6916982f, 4.76402643f, "NGO Site 2"));
            ngoSites.Add(new NGOSiteConfig(24.6807822f, -6.75057337f, "NGO Site 3"));

            // Village
            villages = new List <SiteConfig>();
            villages.Add(new VillageConfig(-16.0197901f, 5.74808437f, "Village 0"));
            villages.Add(new VillageConfig(-14.296086f, -3.22944096f, "Village 1"));
            villages.Add(new VillageConfig(-5.63349131f, 4.74559538f, "Village 2"));
            villages.Add(new VillageConfig(7.34998325f, -0.743652906f, "Village 3"));
            villages.Add(new VillageConfig(-13.4306279f, -11.7638197f, "Village 4"));
        }