File size: 5,352 Bytes
1ef829e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python3
"""
Test script for DAG integration in DART-LLM-Multi-Model
"""

from dag_visualizer import DAGVisualizer
from json_processor import JsonProcessor
import json

def test_dag_integration():
    """Test the DAG integration with sample task data"""
    print("Testing DAG integration...")
    
    # Sample response with task data (similar to what the model might generate)
    sample_response = """
    Based on your command, here are the robot tasks:
    
    {
        "tasks": [
            {
                "task": "move_excavator_to_soil_area",
                "instruction_function": {
                    "name": "move_to_position",
                    "robot_ids": ["robot_excavator_01"],
                    "dependencies": [],
                    "object_keywords": ["soil_area_1"]
                }
            },
            {
                "task": "excavate_soil",
                "instruction_function": {
                    "name": "excavate_material",
                    "robot_ids": ["robot_excavator_01"],
                    "dependencies": ["move_excavator_to_soil_area"],
                    "object_keywords": ["soil"]
                }
            },
            {
                "task": "move_dump_truck",
                "instruction_function": {
                    "name": "move_to_position",
                    "robot_ids": ["robot_dump_truck_01"],
                    "dependencies": [],
                    "object_keywords": ["soil_area_1"]
                }
            },
            {
                "task": "load_soil_to_truck",
                "instruction_function": {
                    "name": "transfer_material",
                    "robot_ids": ["robot_excavator_01", "robot_dump_truck_01"],
                    "dependencies": ["excavate_soil", "move_dump_truck"],
                    "object_keywords": ["soil"]
                }
            },
            {
                "task": "transport_to_dump_site",
                "instruction_function": {
                    "name": "move_to_position",
                    "robot_ids": ["robot_dump_truck_01"],
                    "dependencies": ["load_soil_to_truck"],
                    "object_keywords": ["dump_site"]
                }
            }
        ]
    }
    """
    
    # Test JSON processing
    processor = JsonProcessor()
    print("1. Testing JSON processing...")
    processed_json = processor.process_response(sample_response)
    
    if processed_json:
        print("βœ“ JSON processing successful")
        print(f"   Found {len(processed_json['tasks'])} tasks")
    else:
        print("βœ— JSON processing failed")
        return False
    
    # Test DAG visualization
    print("2. Testing DAG visualization...")
    visualizer = DAGVisualizer()
    
    try:
        dag_image_path = visualizer.create_dag_visualization(
            processed_json, 
            title="Test Robot Task Dependency Graph"
        )
        
        if dag_image_path:
            print(f"βœ“ DAG visualization created: {dag_image_path}")
            return True
        else:
            print("βœ— DAG visualization failed")
            return False
            
    except Exception as e:
        print(f"βœ— DAG visualization error: {e}")
        return False

def test_simplified_dag():
    """Test simplified DAG visualization"""
    print("\n3. Testing simplified DAG...")
    
    simple_task_data = {
        "tasks": [
            {
                "task": "move_robot",
                "instruction_function": {
                    "name": "move_to_position",
                    "robot_ids": ["robot_01"],
                    "dependencies": [],
                    "object_keywords": ["target_area"]
                }
            },
            {
                "task": "perform_operation",
                "instruction_function": {
                    "name": "excavate",
                    "robot_ids": ["robot_01"],
                    "dependencies": ["move_robot"],
                    "object_keywords": ["soil"]
                }
            }
        ]
    }
    
    visualizer = DAGVisualizer()
    
    try:
        dag_image_path = visualizer.create_simplified_dag_visualization(
            simple_task_data,
            title="Simplified Test DAG"
        )
        
        if dag_image_path:
            print(f"βœ“ Simplified DAG visualization created: {dag_image_path}")
            return True
        else:
            print("βœ— Simplified DAG visualization failed")
            return False
            
    except Exception as e:
        print(f"βœ— Simplified DAG visualization error: {e}")
        return False

def main():
    """Run all tests"""
    print("=" * 60)
    print("DART-LLM-Multi-Model DAG Integration Test")
    print("=" * 60)
    
    success_count = 0
    total_tests = 2
    
    if test_dag_integration():
        success_count += 1
    
    if test_simplified_dag():
        success_count += 1
    
    print("\n" + "=" * 60)
    print(f"Test Results: {success_count}/{total_tests} passed")
    
    if success_count == total_tests:
        print("πŸŽ‰ All DAG integration tests passed!")
        return True
    else:
        print("❌ Some tests failed!")
        return False

if __name__ == "__main__":
    success = main()
    exit(0 if success else 1)