问题描述
所以我正在编写一个程序,使用BFS,A *和UCS解决8个难题。根据分配的目标状态已固定:
Goal State:
|1 2 3|
|8 4|
|7 6 5|
My Initial State:
| 1 2|
|8 4 3|
|7 6 5|
但是,在编写getInvCount(int [] a)
方法时:
public static boolean getInvCount(int [] a)
{
int [] arr = a;
int inv_count = 0;
for(int i = 0;i<arr.length-1;i++){
for(int j = i + 1; j < arr.length;j++){
if(arr[i]>arr[j]){
inv_count++;
}
}
}
System.out.println(inv_count);
我意识到初始拼图有9个倒置,这是一个奇数。但是程序成功找到了解决方案。 拼图被认为可以解决的要求中我缺少什么吗?
解决方法
您的#copy data into columns
data = pd.read_csv("data.txt",header=None,engine='python',sep=" ")
force = data.iloc[:,1].copy()
strain = data.iloc[:,2].copy()
#calculate stress
radius = 3.25*10**(-3)
area = np.pi*radius**2
stress = force/area
x_subregion=np.where((np.logical_and(strain>=.04,stress<=.20)))
strainsubvals = strain[x_subregion]
stresssubvals = stress[x_subregion]
函数仅对“ 1 2 3 4 5 6 7 8”目标状态有效。 “反转”是指两个图块以与目标状态不同的顺序排列。如果目标状态严格增加,则比较getInvCount
仅是对反转的正确检查。