From 66ffe4bc9040fa435df6c5d542a941f1ebca43e0 Mon Sep 17 00:00:00 2001 From: Pano Date: Thu, 16 Feb 2023 13:41:26 +0100 Subject: [PATCH 1/2] Removed DecisionRequester() from tests --- .../ML-Agents/packerhand/Scenes/Test_30.unity | 1 + .../packerhand/Scenes/Test_412.unity | 4 +- .../packerhand/Scripts/PackerHand.cs | 78 ++++++++++--------- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/Assets/ML-Agents/packerhand/Scenes/Test_30.unity b/Assets/ML-Agents/packerhand/Scenes/Test_30.unity index 48cf61b9..d7bc15dd 100644 --- a/Assets/ML-Agents/packerhand/Scenes/Test_30.unity +++ b/Assets/ML-Agents/packerhand/Scenes/Test_30.unity @@ -1289,6 +1289,7 @@ PrefabInstance: objectReference: {fileID: 2100000, guid: 1644c0cb0c67e314194579be857f87da, type: 2} m_RemovedComponents: - {fileID: 2674329426616174709, guid: 2f2c1469c0f2c8453ab01d6d68f6526f, type: 3} + - {fileID: 6303212369219772044, guid: 2f2c1469c0f2c8453ab01d6d68f6526f, type: 3} m_RemovedGameObjects: [] m_AddedGameObjects: [] m_AddedComponents: diff --git a/Assets/ML-Agents/packerhand/Scenes/Test_412.unity b/Assets/ML-Agents/packerhand/Scenes/Test_412.unity index af30ddf8..a2e82882 100644 --- a/Assets/ML-Agents/packerhand/Scenes/Test_412.unity +++ b/Assets/ML-Agents/packerhand/Scenes/Test_412.unity @@ -572,7 +572,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: agent: {fileID: 0} - parent_mf: {fileID: 0} isCollidedGreen: 0 isCollidedBlue: 0 isCollidedRed: 0 @@ -748,7 +747,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: agent: {fileID: 0} - parent_mf: {fileID: 0} isCollidedGreen: 0 isCollidedBlue: 0 isCollidedRed: 0 @@ -1291,6 +1289,7 @@ PrefabInstance: objectReference: {fileID: 2100000, guid: 1644c0cb0c67e314194579be857f87da, type: 2} m_RemovedComponents: - {fileID: 2674329426616174709, guid: 2f2c1469c0f2c8453ab01d6d68f6526f, type: 3} + - {fileID: 6303212369219772044, guid: 2f2c1469c0f2c8453ab01d6d68f6526f, type: 3} m_RemovedGameObjects: [] m_AddedGameObjects: [] m_AddedComponents: @@ -1447,7 +1446,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: agent: {fileID: 0} - parent_mf: {fileID: 0} isCollidedGreen: 0 isCollidedBlue: 0 isCollidedRed: 0 diff --git a/Assets/ML-Agents/packerhand/Scripts/PackerHand.cs b/Assets/ML-Agents/packerhand/Scripts/PackerHand.cs index f8304de0..ccb2f213 100644 --- a/Assets/ML-Agents/packerhand/Scripts/PackerHand.cs +++ b/Assets/ML-Agents/packerhand/Scripts/PackerHand.cs @@ -43,7 +43,7 @@ public class PackerHand : Agent public Vector3 [] verticesArray; // space: 2n + 1 Vector3 vertices where n = num boxes [HideInInspector] public int selectedVertexIdx = -1; [HideInInspector] private List boxPool; // space: num boxes - [HideInInspector] private List vertexIndices; + [HideInInspector] private List maskedVertexIndices; [HideInInspector] public List organizedBoxes; // list of organzed box indices [HideInInspector] public List historicalVerticesLog; [HideInInspector] public int VertexCount = 0; @@ -66,7 +66,7 @@ public class PackerHand : Agent [HideInInspector] public bool isEpisodeStart; [HideInInspector] public bool isAfterOriginVertexSelected; //[HideInInspector] public bool isBlackboxUpdated; - public bool isVertexSelected; + // public bool isVertexSelected; public bool isBoxSelected; public bool isRotationSelected; public bool isPickedup; @@ -174,7 +174,7 @@ public override void OnEpisodeBegin() boxSpawner.SetUpBoxes(m_ResetParams.GetWithDefault("regular_box", 0)); selectedVertex = origin; // refactor to select first vertex - isVertexSelected = true; + // isVertexSelected = true; //SetResetParameters(); @@ -214,7 +214,7 @@ public override void CollectObservations(VectorSensor sensor) // Add array of vertices (selected vertices are 0s) int i = 0; - vertexIndices = new List(); + maskedVertexIndices = new List(); foreach (Vector3 vertex in verticesArray) { Vector3 scaled_continuous_vertex = new Vector3(((vertex.x - origin.x)/binscale_x), ((vertex.y - origin.y)/binscale_y), ((vertex.z - origin.z)/binscale_z)); @@ -227,7 +227,7 @@ public override void CollectObservations(VectorSensor sensor) if (vertex == Vector3.zero) { //Debug.Log($"MASK VERTEX LOOP INDEX:{i}"); - vertexIndices.Add(i); + maskedVertexIndices.Add(i); } i++; } @@ -251,7 +251,7 @@ public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { // vertices action mask if (isAfterOriginVertexSelected) { - foreach (int vertexIdx in vertexIndices) + foreach (int vertexIdx in maskedVertexIndices) { //Debug.Log($"MASK VERTEX {vertexIdx}"); actionMask.SetActionEnabled(0, vertexIdx, false); @@ -652,7 +652,7 @@ public void SelectVertex(int action_SelectedVertex) selectedVertex = new Vector3(((unscaled_selectedVertex.x* binscale_x) + origin.x), ((unscaled_selectedVertex.y* binscale_y) + origin.y), ((unscaled_selectedVertex.z* binscale_z) + origin.z)); Debug.Log($"SVX Selected VerteX: {selectedVertex}"); - isVertexSelected = true; + // isVertexSelected = true; //AddReward(1f); // Debug.Log($"RWD {GetCumulativeReward()} total reward | +1 reward from isVertexSelected: {isVertexSelected}"); } @@ -1136,36 +1136,38 @@ public void ReverseSideNames(int id) } - public void BoxReset(string cause) - { - if (cause == "failedPhysicsCheck") - { - Debug.Log($"SCS BOX {selectedBoxIdx} RESET LOOP, BOX POOL COUNT IS {boxPool.Count}"); - // detach box from agent - targetBox.parent = null; - // add back rigidbody and collider - Rigidbody rb = boxPool[selectedBoxIdx].rb; - BoxCollider bc = boxPool[selectedBoxIdx].rb.gameObject.AddComponent(); - // not be affected by forces or collisions, position and rotation will be controlled directly through script - rb.isKinematic = true; - // reset to starting position - rb.transform.localScale = boxPool[selectedBoxIdx].startingSize; - rb.transform.rotation = boxPool[selectedBoxIdx].startingRot; - rb.transform.position = boxPool[selectedBoxIdx].startingPos; - ReverseSideNames(selectedBoxIdx); - // remove from organized list to be picked again - organizedBoxes.Remove(selectedBoxIdx); - // reset states - StateReset(); - // REQUEST DECISION FOR THE NEXT ROUND OF PICKING - GetComponent().RequestDecision(); - Academy.Instance.EnvironmentStep(); - // settting isBlackboxUpdated to true allows another vertex to be selected - //isBlackboxUpdated = true; - // setting isVertexSelected to true keeps the current vertex and allows another box to be selected - // isVertexSelected = true; - } - } +// public void BoxReset(string cause) +// { +// if (cause == "failedPhysicsCheck") +// { +// Debug.Log($"SCS BOX {selectedBoxIdx} RESET LOOP, BOX POOL COUNT IS {boxPool.Count}"); +// // detach box from agent +// targetBox.parent = null; +// // add back rigidbody and collider +// Rigidbody rb = boxPool[selectedBoxIdx].rb; +// BoxCollider bc = boxPool[selectedBoxIdx].rb.gameObject.AddComponent(); +// // not be affected by forces or collisions, position and rotation will be controlled directly through script +// rb.isKinematic = true; +// // reset to starting position +// rb.transform.localScale = boxPool[selectedBoxIdx].startingSize; +// rb.transform.rotation = boxPool[selectedBoxIdx].startingRot; +// rb.transform.position = boxPool[selectedBoxIdx].startingPos; +// ReverseSideNames(selectedBoxIdx); +// // remove from organized list to be picked again +// // to "be picked again" means to be added back to the boxPool?? +// organizedBoxes.Remove(selectedBoxIdx); +// // reset states +// StateReset(); +// // REQUEST DECISION FOR THE NEXT ROUND OF PICKING +// // Why is the DecisionRequester() still active in the Hand gameObject? +// GetComponent().RequestDecision(); +// Academy.Instance.EnvironmentStep(); +// // settting isBlackboxUpdated to true allows another vertex to be selected +// //isBlackboxUpdated = true; +// // setting isVertexSelected to true keeps the current vertex and allows another box to be selected +// // isVertexSelected = true; +// } +// } public void AgentReset() @@ -1200,7 +1202,7 @@ public void StateReset() boxPool[selectedBoxIdx].boxRot = default_rotation; } //isBlackboxUpdated = false; - isVertexSelected = false; + // isVertexSelected = false; isBoxSelected = false; isRotationSelected = false; isPickedup = false; From c2e6e7d2062a621d33730fa8b6d34a901cb12066 Mon Sep 17 00:00:00 2001 From: Pano Date: Thu, 16 Feb 2023 14:54:26 +0100 Subject: [PATCH 2/2] DiscreteSolution boolean and Test_30 back to original --- .../packerhand/Scripts/Boxes_30.json | 6 +- .../packerhand/Scripts/PackerHand.cs | 235 +++++++++--------- 2 files changed, 115 insertions(+), 126 deletions(-) diff --git a/Assets/ML-Agents/packerhand/Scripts/Boxes_30.json b/Assets/ML-Agents/packerhand/Scripts/Boxes_30.json index c631424c..01fc62dd 100644 --- a/Assets/ML-Agents/packerhand/Scripts/Boxes_30.json +++ b/Assets/ML-Agents/packerhand/Scripts/Boxes_30.json @@ -2,9 +2,9 @@ "Items": [ { "Product_id": 0, - "Length": 10.70, - "Width": 20.45, - "Height": 20.85, + "Length": 14.70, + "Width": 23.45, + "Height": 23.85, "Quantity": 1 }, { diff --git a/Assets/ML-Agents/packerhand/Scripts/PackerHand.cs b/Assets/ML-Agents/packerhand/Scripts/PackerHand.cs index 98bb1836..19fd5f5c 100644 --- a/Assets/ML-Agents/packerhand/Scripts/PackerHand.cs +++ b/Assets/ML-Agents/packerhand/Scripts/PackerHand.cs @@ -178,8 +178,8 @@ public override void OnEpisodeBegin() if(discreteSolution){ selectedVertex = origin; // refactor to select first vertex // isVertexSelected = true; + //SetResetParameters(); } - //SetResetParameters(); } @@ -268,7 +268,12 @@ public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask) foreach (int selectedBoxIdx in organizedBoxes) { //Debug.Log($"MASK BOX {selectedBoxIdx}"); - actionMask.SetActionEnabled(0, selectedBoxIdx, false); + if (discreteSolution){ + actionMask.SetActionEnabled(1, selectedBoxIdx, false); + } + else { + actionMask.SetActionEnabled(0, selectedBoxIdx, false); + } } } @@ -282,13 +287,19 @@ public override void OnActionReceived(ActionBuffers actionBuffers) Debug.Log($"ON ACTION RECEIVED ACTION ZERO: {discreteActions[0]}"); Debug.Log($"ON ACTION RECEIVED ACTION ONE: {discreteActions[1]}"); - // Debug.Log($"ON ACTION RECEIVED ACTION TWO: {discreteActions[2]}"); - var continuousActions = actionBuffers.ContinuousActions; - - //SelectVertex(discreteActions[++j]); - SelectBox(discreteActions[++j]); - SelectRotation(discreteActions[++j]); - SelectContinuousVertex(continuousActions[++i], continuousActions[++i], continuousActions[++i]); + if (discreteSolution){ + Debug.Log($"ON ACTION RECEIVED ACTION TWO: {discreteActions[2]}"); + SelectVertex(discreteActions[++j]); + SelectBox(discreteActions[++j]); + SelectRotation(discreteActions[++j]); + } + else { + var continuousActions = actionBuffers.ContinuousActions; + + SelectBox(discreteActions[++j]); + SelectRotation(discreteActions[++j]); + SelectContinuousVertex(continuousActions[++i], continuousActions[++i], continuousActions[++i]); + } } @@ -322,7 +333,9 @@ void FixedUpdate() { isEpisodeStart = false; // REQUEST DECISION FOR FIRST ROUND OF PICKING - isAfterOriginVertexSelected = false; + if (discreteSolution){ + isAfterOriginVertexSelected = false; + } //Debug.Log("BEFORE INITIAL ENVIRONEMTN STEP IN FIRST ROUND"); GetComponent().RequestDecision(); //Debug.Log("BEFORE ENVIRONEMTN STEP IN FIRST ROUND"); @@ -335,10 +348,13 @@ void FixedUpdate() StateReset(); - //isAfterOriginVertexSelected = true; - // vertices array of tripoints doesn't depend on the trimesh - // only update vertices list and vertices array when box is placed - //UpdateVerticesArray(); + if (discreteSolution){ + isAfterOriginVertexSelected = true; + // vertices array of tripoints doesn't depend on the trimesh + // only update vertices list and vertices array when box is placed + UpdateVerticesArray(); + } + // side, back, and bottom vertices lists depends on the trimesh // should be commented out if not using blackbox for better performance //UpdateVerticesList(); @@ -483,16 +499,16 @@ void UpdateTargetBox() // } - // void UpdateVerticesArray() - // { - // List tripoints_list = new List(); - // var tripoint_redx = new Vector3(selectedVertex.x + boxWorldScale.x, selectedVertex.y, selectedVertex.z); // x red side tripoint - // var tripoint_greeny = new Vector3(selectedVertex.x, selectedVertex.y+boxWorldScale.y, selectedVertex.z); // y green bottom tripoint - // var tripoint_bluez = new Vector3(selectedVertex.x, selectedVertex.y, selectedVertex.z+boxWorldScale.z); // z blue back tripoint + void UpdateVerticesArray() + { + List tripoints_list = new List(); + var tripoint_redx = new Vector3(selectedVertex.x + boxWorldScale.x, selectedVertex.y, selectedVertex.z); // x red side tripoint + var tripoint_greeny = new Vector3(selectedVertex.x, selectedVertex.y+boxWorldScale.y, selectedVertex.z); // y green bottom tripoint + var tripoint_bluez = new Vector3(selectedVertex.x, selectedVertex.y, selectedVertex.z+boxWorldScale.z); // z blue back tripoint - // tripoints_list.Add(tripoint_redx); - // tripoints_list.Add(tripoint_greeny); - // tripoints_list.Add(tripoint_bluez); + tripoints_list.Add(tripoint_redx); + tripoints_list.Add(tripoint_greeny); + tripoints_list.Add(tripoint_bluez); // comment out the 4 lines below if want only 3 vertices // var tripoint_xy = new Vector3(selectedVertex.x + boxWorldScale.x, selectedVertex.y+boxWorldScale.y, selectedVertex.z); @@ -507,33 +523,33 @@ void UpdateTargetBox() // tripoints_list.Add(tripoint_yz); - // for (int idx = 0; idx= areaBounds.min.x && tripoints_list[idx].x < areaBounds.max.x) { - // if (tripoints_list[idx].y >= areaBounds.min.y && tripoints_list[idx].y < areaBounds.max.y) { - // if (tripoints_list[idx].z >= areaBounds.min.z && tripoints_list[idx].z < areaBounds.max.z) { - // // only if historicVerticesArray doesnt already contain the tripoint, add it to the verticesArray - // // Vector3 scaled_continuous_vertex = new Vector3(((tripoints_list[idx].x - origin.x)/binscale_x), ((tripoints_list[idx].y - origin.y)/binscale_y), ((tripoints_list[idx].z - origin.z)/binscale_z)); - // //Vector3 = new Vector3((float)Math.Round(((tripoints_list[idx].x - origin.x)/binscale_x), 4), (float)Math.Round(((tripoints_list[idx].y - origin.y)/binscale_y), 4), (float)Math.Round(((tripoints_list[idx].z - origin.z)/binscale_z), 4)); - // Vector3 scaled_continuous_vertex = new Vector3((tripoints_list[idx].x - origin.x)/binscale_x, (tripoints_list[idx].y - origin.y)/binscale_y, (tripoints_list[idx].z - origin.z)/binscale_z); - // //Vector3 rounded_scaled_vertex = new Vector3((float)Math.Round(scaled_continuous_vertex.x, 2), (float)Math.Round(scaled_continuous_vertex.y, 2), (float)Math.Round(scaled_continuous_vertex.y, 2)); - // Debug.Log($"VACx historicalVerticesLog.Exists(element => element == scaled_continuous_vertex) == false: {historicalVerticesLog.Exists(element => element == scaled_continuous_vertex) == false} | scaled_continuous_vertex: {scaled_continuous_vertex} "); - // if ( historicalVerticesLog.Exists(element => element == scaled_continuous_vertex) == false ) - // { - // Debug.Log($"TPX idx:{idx} | tripoint add to tripoints_list[idx]: {tripoints_list[idx]} | selectedVertex: {selectedVertex}") ; - // // Add scaled tripoint_vertex to verticesArray - // verticesArray[VertexCount] = scaled_continuous_vertex; - // historicalVerticesLog.Add(scaled_continuous_vertex); - // VertexCount ++; - // Debug.Log($"VERTEX COUNT IS {VertexCount}"); - - // } - // } - // } - // } - // } - // } + for (int idx = 0; idx= areaBounds.min.x && tripoints_list[idx].x < areaBounds.max.x) { + if (tripoints_list[idx].y >= areaBounds.min.y && tripoints_list[idx].y < areaBounds.max.y) { + if (tripoints_list[idx].z >= areaBounds.min.z && tripoints_list[idx].z < areaBounds.max.z) { + // only if historicVerticesArray doesnt already contain the tripoint, add it to the verticesArray + // Vector3 scaled_continuous_vertex = new Vector3(((tripoints_list[idx].x - origin.x)/binscale_x), ((tripoints_list[idx].y - origin.y)/binscale_y), ((tripoints_list[idx].z - origin.z)/binscale_z)); + //Vector3 = new Vector3((float)Math.Round(((tripoints_list[idx].x - origin.x)/binscale_x), 4), (float)Math.Round(((tripoints_list[idx].y - origin.y)/binscale_y), 4), (float)Math.Round(((tripoints_list[idx].z - origin.z)/binscale_z), 4)); + Vector3 scaled_continuous_vertex = new Vector3((tripoints_list[idx].x - origin.x)/binscale_x, (tripoints_list[idx].y - origin.y)/binscale_y, (tripoints_list[idx].z - origin.z)/binscale_z); + //Vector3 rounded_scaled_vertex = new Vector3((float)Math.Round(scaled_continuous_vertex.x, 2), (float)Math.Round(scaled_continuous_vertex.y, 2), (float)Math.Round(scaled_continuous_vertex.y, 2)); + Debug.Log($"VACx historicalVerticesLog.Exists(element => element == scaled_continuous_vertex) == false: {historicalVerticesLog.Exists(element => element == scaled_continuous_vertex) == false} | scaled_continuous_vertex: {scaled_continuous_vertex} "); + if ( historicalVerticesLog.Exists(element => element == scaled_continuous_vertex) == false ) + { + Debug.Log($"TPX idx:{idx} | tripoint add to tripoints_list[idx]: {tripoints_list[idx]} | selectedVertex: {selectedVertex}") ; + // Add scaled tripoint_vertex to verticesArray + verticesArray[VertexCount] = scaled_continuous_vertex; + historicalVerticesLog.Add(scaled_continuous_vertex); + VertexCount ++; + Debug.Log($"VERTEX COUNT IS {VertexCount}"); + + } + } + } + } + } + } // public void UpdateBlackBox() @@ -608,83 +624,53 @@ void UpdateTargetBox() public void SelectContinuousVertex(float action_SelectedVertex_x, float action_SelectedVertex_y, float action_SelectedVertex_z) { - if (discreteSolution){ - // Mathf.Clamp(action_selectVertex[0], -1, 1); - // Mathf.Clamp(action_selectVertex[1], -1, 1); - // Mathf.Clamp(action_selectVertex[2], -1, 1); - - Debug.Log($"SVB brain selected vertex #: {action_SelectedVertex} "); - - - // Don't select empty vertex (0,0,0) from actionBuffer. Punish to teach it to learn not to pick empty ~ give negative reward and force to repick. - // if (verticesArray[action_SelectedVertex] == new Vector3(0, 0, 0)) - // { - // isVertexSelected = false; // to make repick SelectVertex(discreteActions[++j]) - // // Punish agent for selecting a bad position - // //AddReward(-1f); - // // Debug.Log($"REWARD NEGATIVE SELECTED ZERO VERTEX!!! Total reward: {GetCumulativeReward()}"); - // return; // to end function call - // } - - // assign selected vertex where next box will be placed, selected from brain's actionbuffer (inputted as action_SelectedVertex) - selectedVertexIdx = action_SelectedVertex; - var unscaled_selectedVertex = verticesArray[action_SelectedVertex]; - selectedVertex = new Vector3(((unscaled_selectedVertex.x* binscale_x) + origin.x), ((unscaled_selectedVertex.y* binscale_y) + origin.y), ((unscaled_selectedVertex.z* binscale_z) + origin.z)); + action_SelectedVertex_x = (action_SelectedVertex_x + 1f) * 0.5f; + action_SelectedVertex_y = (action_SelectedVertex_y + 1f) * 0.5f; + action_SelectedVertex_z = (action_SelectedVertex_z + 1f) * 0.5f; + if (curriculum_ConfigurationLocal==1) + { + // fix box scale so box always packs from bottom up + //float y = boxWorldScale.y * 0.5f + 0.5f; + selectedVertex = new Vector3(((action_SelectedVertex_x* binscale_x) + origin.x), 0.5f, ((action_SelectedVertex_z* binscale_z) + origin.z)); Debug.Log($"SVX Selected VerteX: {selectedVertex}"); - - // isVertexSelected = true; - //AddReward(1f); - // Debug.Log($"RWD {GetCumulativeReward()} total reward | +1 reward from isVertexSelected: {isVertexSelected}"); } - else { - action_SelectedVertex_x = (action_SelectedVertex_x + 1f) * 0.5f; - action_SelectedVertex_y = (action_SelectedVertex_y + 1f) * 0.5f; - action_SelectedVertex_z = (action_SelectedVertex_z + 1f) * 0.5f; - if (curriculum_ConfigurationLocal==1) - { - // fix box scale so box always packs from bottom up - //float y = boxWorldScale.y * 0.5f + 0.5f; - selectedVertex = new Vector3(((action_SelectedVertex_x* binscale_x) + origin.x), 0.5f, ((action_SelectedVertex_z* binscale_z) + origin.z)); - Debug.Log($"SVX Selected VerteX: {selectedVertex}"); - } - else if (curriculum_ConfigurationLocal==2) - { - selectedVertex = new Vector3(((action_SelectedVertex_x* binscale_x) + origin.x), ((action_SelectedVertex_y* binscale_y) + origin.y), ((action_SelectedVertex_z* binscale_z) + origin.z)); - } - // isVertexSelected = true; + else if (curriculum_ConfigurationLocal==2) + { + selectedVertex = new Vector3(((action_SelectedVertex_x* binscale_x) + origin.x), ((action_SelectedVertex_y* binscale_y) + origin.y), ((action_SelectedVertex_z* binscale_z) + origin.z)); } + // isVertexSelected = true; } - // public void SelectVertex(int action_SelectedVertex) - // { - // // Mathf.Clamp(action_selectVertex[0], -1, 1); - // // Mathf.Clamp(action_selectVertex[1], -1, 1); - // // Mathf.Clamp(action_selectVertex[2], -1, 1); + public void SelectVertex(int action_SelectedVertex) + { + // Mathf.Clamp(action_selectVertex[0], -1, 1); + // Mathf.Clamp(action_selectVertex[1], -1, 1); + // Mathf.Clamp(action_selectVertex[2], -1, 1); - // Debug.Log($"SVB brain selected vertex #: {action_SelectedVertex} "); + Debug.Log($"SVB brain selected vertex #: {action_SelectedVertex} "); - // // Don't select empty vertex (0,0,0) from actionBuffer. Punish to teach it to learn not to pick empty ~ give negative reward and force to repick. - // // if (verticesArray[action_SelectedVertex] == new Vector3(0, 0, 0)) - // // { - // // isVertexSelected = false; // to make repick SelectVertex(discreteActions[++j]) - // // // Punish agent for selecting a bad position - // // //AddReward(-1f); - // // // Debug.Log($"REWARD NEGATIVE SELECTED ZERO VERTEX!!! Total reward: {GetCumulativeReward()}"); - // // return; // to end function call - // // } + // Don't select empty vertex (0,0,0) from actionBuffer. Punish to teach it to learn not to pick empty ~ give negative reward and force to repick. + // if (verticesArray[action_SelectedVertex] == new Vector3(0, 0, 0)) + // { + // isVertexSelected = false; // to make repick SelectVertex(discreteActions[++j]) + // // Punish agent for selecting a bad position + // //AddReward(-1f); + // // Debug.Log($"REWARD NEGATIVE SELECTED ZERO VERTEX!!! Total reward: {GetCumulativeReward()}"); + // return; // to end function call + // } - // // assign selected vertex where next box will be placed, selected from brain's actionbuffer (inputted as action_SelectedVertex) - // selectedVertexIdx = action_SelectedVertex; - // var unscaled_selectedVertex = verticesArray[action_SelectedVertex]; - // selectedVertex = new Vector3(((unscaled_selectedVertex.x* binscale_x) + origin.x), ((unscaled_selectedVertex.y* binscale_y) + origin.y), ((unscaled_selectedVertex.z* binscale_z) + origin.z)); - // Debug.Log($"SVX Selected VerteX: {selectedVertex}"); + // assign selected vertex where next box will be placed, selected from brain's actionbuffer (inputted as action_SelectedVertex) + selectedVertexIdx = action_SelectedVertex; + var unscaled_selectedVertex = verticesArray[action_SelectedVertex]; + selectedVertex = new Vector3(((unscaled_selectedVertex.x* binscale_x) + origin.x), ((unscaled_selectedVertex.y* binscale_y) + origin.y), ((unscaled_selectedVertex.z* binscale_z) + origin.z)); + Debug.Log($"SVX Selected VerteX: {selectedVertex}"); - // isVertexSelected = true; - // //AddReward(1f); - // // Debug.Log($"RWD {GetCumulativeReward()} total reward | +1 reward from isVertexSelected: {isVertexSelected}"); - // } + // isVertexSelected = true; + //AddReward(1f); + // Debug.Log($"RWD {GetCumulativeReward()} total reward | +1 reward from isVertexSelected: {isVertexSelected}"); + } public void UpdateBoxPosition() @@ -1216,13 +1202,16 @@ public void StateReset() if (isBackMeshCombined | isSideMeshCombined | isBottomMeshCombined) { //if (selectedVertexIdx != -1) - // if (isAfterOriginVertexSelected) - // { - // Debug.Log($"SRS SELECTED VERTEX IDX {selectedVertexIdx} RESET"); - // Vector3 default_vertex = Vector3.zero; - // verticesArray[selectedVertexIdx] = default_vertex; - // } + if (discreteSolution){ + if (isAfterOriginVertexSelected) + { + Debug.Log($"SRS SELECTED VERTEX IDX {selectedVertexIdx} RESET"); + Vector3 default_vertex = Vector3.zero; + verticesArray[selectedVertexIdx] = default_vertex; + } + } // Debug.Log($"SRS SELECTED BOX IDX {selectedBoxIdx} RESET"); + Vector3 default_size = Vector3.zero; boxPool[selectedBoxIdx].boxSize = default_size; Debug.Log($"SRS SELECTED ROTATION {selectedRotation} RESET"); @@ -1309,7 +1298,7 @@ void ConfigureAgent(int n) } else { - SetModel(m_RegularBoxBehaviorName, regularBoxBrain); + SetModel(m_SimilarBoxBehaviorName, similarBoxBrain); Debug.Log($"BOX POOL SIZE: {boxPool.Count}"); } }