Gradescope中Raven矩阵项目代码异常:Solve方法传参求助
Gradescope Raven渐进矩阵项目执行问题排查与解决
问题原因分析
- 手动构造
image_path的方式完全错误:Gradescope环境中题目是随机打乱的,硬编码的路径(比如os.path.join('Basic Problems B', 'Basic Problem B-02', 'Basic Problem B-02.png'))根本无法匹配实际运行时的文件位置 - 误解了
Solve方法的参数传递逻辑:problem实例已经封装了当前题目所有图形的资源信息,不需要自行拼接路径
TA的反馈原文:
"I think your issue is how you are trying to access the problem names and are overcomplicating the process. You shouldn't be trying to construct the problem names yourself as these are shuffled and randomized in the gradescope environment. Everything you need is passed into the Agent solve method. Using problem.figures["A"].visualFilename is all that is required to get the image A.png file from the dictionary supplied to the agent. Please try this approach to see if that simples the processing by the agent."
解决建议
- 直接使用
problem.figures获取文件路径:problem.figures是一个字典,键为图形标识(比如"A"、"B"、"1"到"6"),对应的值包含visualFilename字段,这个字段就是当前图形文件的正确相对路径,不需要自己拼接 - 不要修改工作目录:Gradescope运行环境已经配置好文件路径上下文,直接使用
visualFilename的值即可打开文件 - 修改
Solve方法示例:替换手动构造路径的代码,改用problem.figures获取文件名,示例如下:
class Agent: def __init__(self): pass def Solve(self, problem): # 获取题目中A图形的文件名 a_img_path = problem.figures["A"].visualFilename # 示例:打开文件进行预处理 # image_a = self.preprocess_image(a_img_path) # 获取选项1的文件名 option1_path = problem.figures["1"].visualFilename # 实现你的解题逻辑,最后返回1-6之间的答案(不要返回-1,除非确实要跳过) return 1
内容的提问来源于stack exchange,提问作者dionysus
相关产品推荐
相关产品推荐

