void Start() { packingAgent = GetComponent <PackingAgent>(); packEvol = GetComponent <PackEvolver>(); // setting up global variables GRID_RES = packingAgent.MOV_RES + 1; GRID_SIZE = 1f / (float)GRID_RES; }
// Converts index to continous position // if isStart0 is false, idx assummed to be in (1, 25)^3 public Vector3 IdxToConPos(Vector3 idx, bool isStart0) { // local import so as to run the packing agent code without the start function packEvol = GetComponent <PackEvolver>(); if (isStart0) { idx += Vector3.one; } return(GRID_SIZE * idx + packEvol.BOX_BLB_CORNER); }
// Converts continuos postion to index // if isStart0 is false, idx assummed to be in (1, 25)^3 public Vector3Int ConToIdxPos(Vector3 con, bool isStart0) { // local import so as to run the packing agent code without the start function packEvol = GetComponent <PackEvolver>(); Vector3 _idx = (con - packEvol.BOX_BLB_CORNER) * ((float)GRID_RES); if (!IsFloatInt(_idx.x) || !IsFloatInt(_idx.y) || !IsFloatInt(_idx.z)) { Debug.Log("Error converting wrong cont. position to idx."); } Vector3Int idx = new Vector3Int(FloatToInt(_idx.x), FloatToInt(_idx.y), FloatToInt(_idx.z)); if (isStart0) { idx -= Vector3Int.one; } return(idx); }
void Start() { // getting the required components packEvol = GetComponent <PackEvolver>(); gtPack = GetComponent <GtPack>(); helper = GetComponent <Helper>(); precompute = GetComponent <Precompute>(); // setting up global variables GRID_RES = MOV_RES + 1; GRID_SIZE = 1f / (float)GRID_RES; helper.RESOLUTION = 0.0125f; if (!Application.isEditor) { // getting the command line arguments var args = System.Environment.GetCommandLineArgs(); for (int i = 0; i < args.Length; i++) { if (args[i].ToString() == "-fileName" && args.Length > i + 1) { packFileName = args[i + 1].ToString(); } if (args[i].ToString() == "-packID" && args.Length > i + 1) { packID = Int32.Parse(args[i + 1]); } if (args[i].ToString() == "-getGT" && args.Length > i + 1) { string _getGT = args[i + 1].ToString(); if (_getGT == "true") { getGT = true; } else { getGT = false; } } if (args[i].ToString() == "-getSavedAct" && args.Length > i + 1) { string _getSavedAct = args[i + 1].ToString(); if (_getSavedAct == "true") { getSavedAct = true; } else { getSavedAct = false; } } if (args[i].ToString() == "-actFileName" && args.Length > i + 1) { actFileName = args[i + 1].ToString(); } if (args[i].ToString() == "-rotBeforeMov" && args.Length > i + 1) { string _rotBeforeMov = args[i + 1].ToString(); if (_rotBeforeMov == "true") { rotBeforeMov = true; } else { rotBeforeMov = false; } } if (args[i].ToString() == "-loadPrecompute" && args.Length > i + 1) { string _loadPrecompute = args[i + 1].ToString(); if (_loadPrecompute == "true") { loadPrecompute = true; } else { loadPrecompute = false; } } } } if (editorMode) { Debug.Assert(getGT || getSavedAct); } if (demoMode) { Debug.Assert((getGT || getSavedAct)); Debug.Assert(editorMode); Debug.Assert(!loadPrecompute); } if (getSavedAct) { Debug.Assert(!getGT); Debug.Assert(editorMode || demoMode); Debug.Assert(rotBeforeMov); } }
// Use this for initialization void Start() { packEvol = GetComponent <PackEvolver>(); gtPack = GetComponent <GtPack>(); packingAgent = GetComponent <PackingAgent>(); }
// Use this for initialization void Start() { pack = GetComponent <PackEvolver> (); if (!editorMode) { // gettting the command line arguments var args = System.Environment.GetCommandLineArgs(); for (int i = 0; i < args.Length; i++) { if (args[i].ToString() == "-fileName" && args.Length > i + 1) { fileName = args [i + 1].ToString(); } if (args[i].ToString() == "-shapeNet" && args.Length > i + 1) { shapeNet = args[i + 1].ToString(); } if (args[i].ToString() == "-numPacks" && args.Length > i + 1) { numPacks = int.Parse(args[i + 1].ToString()); } if (args[i].ToString() == "-numChromoGen" && args.Length > i + 1) { numChromoGen = int.Parse(args[i + 1].ToString()); } if (args[i].ToString() == "-numGen" && args.Length > i + 1) { numGen = int.Parse(args[i + 1].ToString()); } if (args[i].ToString() == "-numGenBreak" && args.Length > i + 1) { numGenBreak = int.Parse(args[i + 1].ToString()); } if (args[i].ToString() == "-useEmptySpace" && args.Length > i + 1) { _useEmptySpace = args[i + 1].ToString(); } if (args[i].ToString() == "-initLargestShape" && args.Length > i + 1) { _initLargestShape = args[i + 1].ToString(); } if (args[i].ToString() == "-resolution" && args.Length > i + 1) { resolution = float.Parse(args[i + 1].ToString()); } if (args[i].ToString() == "-seed" && args.Length > i + 1) { seed = int.Parse(args[i + 1].ToString()); } if (args[i].ToString() == "-runAblation" && args.Length > i + 1) { _runAblation = args[i + 1].ToString(); } } } pack.NUM_CHROMO_GEN = numChromoGen; pack.NUM_GEN = numGen; pack.NUM_GEN_BREAK = numGenBreak; pack.RESOLUTION = resolution; packStart = true; Random.InitState(seed); if (_useEmptySpace == "true") { useEmptySpace = true; } else { useEmptySpace = false; } if (_initLargestShape == "true") { initLargestShape = true; } else { initLargestShape = false; } if (_runAblation == "true") { runAblation = true; } else { runAblation = false; } if (!runAblation) { string path = Application.streamingAssetsPath + "/" + fileName + "_log"; string oldOutput = ""; if (File.Exists(path)) { oldOutput = File.ReadAllText(path); } string output = "Experiment Parameters: " + "\n" + "NUM_CHROMO_GEN: " + pack.NUM_CHROMO_GEN + "\n" + "NUM_GEN: " + pack.NUM_GEN + "\n" + "NUM NUM_GEN_BREAK: " + pack.NUM_GEN_BREAK + "\n" + "RESOLUTION: " + pack.RESOLUTION + "\n" + "useEmptySpace: " + useEmptySpace + "\n" + "initLargestShape: " + initLargestShape; File.WriteAllText(path, oldOutput + "\n" + output); } }
// Tighten and Connect the Pack public int[,] TightConPack(ref Pack pack) { PackEvolver packEvol = GetComponent <PackEvolver>(); GameObject[] shapes = packEvol.VisualizePack(pack, loadFromResources: false, keepRenderer: false); // An Adjagency matrix. The (n+1)th node represents the bottom int[,] shapeCon = new int[shapes.Length + 1, shapes.Length + 1]; for (int i = 0; i < shapes.Length; i++) { List <int> conBotIdx = GetConnectedNodes(shapes.Length, shapeCon); // unConBotIdx: unconnected to bottom index int unConBotIdx = -1; for (int j = 0; j < shapes.Length; j++) { if (!conBotIdx.Contains(j)) { unConBotIdx = j; break; } } Debug.Assert(unConBotIdx != -1, "Error in code as all nodes already connected to bottom"); // List of nodes that are connected to unConBotIdx List <int> unConBotIdxs = GetConnectedNodes(unConBotIdx, SubArray2D(shapeCon, 0, shapes.Length, 0, shapes.Length)); foreach (int idx in unConBotIdxs) { packEvol.SetLayerRecursively(shapes[idx], 11); } int minUnConBotIdx = -1; int minUnConBotVal = 100; int minUnConBotCon = -1; foreach (int idx in unConBotIdxs) { var temp = FindNextCon(shapes[idx], shapes.Length); if (temp.Item2 < minUnConBotVal) { minUnConBotIdx = idx; minUnConBotVal = temp.Item2; minUnConBotCon = temp.Item1; } } shapeCon[minUnConBotIdx, minUnConBotCon] = 1; shapeCon[minUnConBotCon, minUnConBotIdx] = 1; foreach (int idx in unConBotIdxs) { Vector3 temp = shapes[idx].transform.position; temp.y -= ((float)minUnConBotVal) * GRID_SIZE; shapes[idx].transform.position = temp; packEvol.SetLayerRecursively(shapes[idx], 0); } } int shapesLength = shapes.Length; for (int i = 0; i < shapesLength; i++) { pack.positions[i] = shapes[i].transform.position; UnityEngine.Object.DestroyImmediate(shapes[i]); } return(shapeCon); }