duh 6 роки тому
батько
коміт
8bb8ce90dd
2 змінених файлів з 50 додано та 19 видалено
  1. 44 17
      phxb/utils/GetAllModule.py
  2. 6 2
      phxb/utils/main.py

+ 44 - 17
phxb/utils/GetAllModule.py

@@ -39,15 +39,23 @@ def printTheTypeObject(type):
     conf.myprint(text.name)
 # 保存正确方案的分数
 def addCurrentScoreToScores(moveResult):
-  temp = []
-  for item in currentScore:
-    temp.append(item)
+  conf.myprint("moveResult=",moveResult)
   if moveResult > 0:
+    temp = []
+    for item in currentScore:
+      temp.append(item)
     scores.append(temp)
+# 获取列表的第二个元素
+def takeSecond(elem):
+  return elem[1]
 # 根据scores给方案打分
 def scoreModule():
   moduleScores = []
-  tempLength = len(scores[0])-1
+  if len(scores)>0:
+    tempLength = len(scores[0])-1
+  else:
+    conf.myprint("scores is empty")
+    return
   # socres中目前存储  位置、入口雷达半径、入口与模块连线长度、模块间连线长度,入口与模块间撞点,模块与模块间撞点
   maxs = [0]*tempLength
   mins = [0]*tempLength
@@ -57,23 +65,45 @@ def scoreModule():
   # 先获取最大值和最小值
   for item in scores:
     for itemIndex in range(tempLength):
+      if maxs[itemIndex]==0:
+        maxs.pop(itemIndex)
+        maxs.insert(itemIndex,item[itemIndex+1])
+      if mins[itemIndex]==0:
+        mins.pop(itemIndex)
+        mins.insert(itemIndex,item[itemIndex+1])
       if item[itemIndex+1]>maxs[itemIndex]:
         maxs.pop(itemIndex)
         maxs.insert(itemIndex,item[itemIndex+1])
-      elif item[itemIndex+1]<mins[itemIndex]:
+      if item[itemIndex+1]<mins[itemIndex]:
         mins.pop(itemIndex)
         mins.insert(itemIndex,item[itemIndex+1])
   for i in range(tempLength):
-    detarLength[i] = maxs[i]-min(i)
-  templateScore = []
+    detarLength[i] = maxs[i]-mins[i]
+  conf.myprint("maxs=",maxs)
+  conf.myprint("mins=",mins)
+  conf.myprint("detarLength=",detarLength)
   for item in scores:
-    templateScore.append(item[0])
+    tempScore = []
+    tempScore.append(item[0])
     for itemIndex in range(tempLength):
-      if(fullSocresDirect[itemIndex] == 1):
-        templateScore.append((item[itemIndex+1]-mins[itemIndex])*fullSocres[itemIndex]/detarLength[itemIndex])
+      if detarLength[itemIndex] == 0:
+        if fullSocresDirect[itemIndex] == 1:
+          tempScore.append(fullSocres[itemIndex])
+        else:
+          tempScore.append(0)
+      elif(fullSocresDirect[itemIndex] == 1):
+        value = (item[itemIndex+1]-mins[itemIndex])*fullSocres[itemIndex]/detarLength[itemIndex]
+        tempScore.append(round(value,2))
       else:
-        templateScore.append(fullSocres[itemIndex] - (item[itemIndex+1]-mins[itemIndex])*fullSocres[itemIndex]/detarLength[itemIndex])
-    moduleScores.append(templateScore)
+        value = fullSocres[itemIndex] - (item[itemIndex+1]-mins[itemIndex])*fullSocres[itemIndex]/detarLength[itemIndex]
+        tempScore.append(round(value,2))
+    tempTotalScore = 0;
+    for i in range(1,len(tempScore)):
+      tempTotalScore += tempScore[i]
+    tempScore.insert(1,tempTotalScore)
+    moduleScores.append(tempScore)
+  conf.myprint("moduleScores=",moduleScores)
+  moduleScores.sort(key=takeSecond,reverse=True)
   conf.myprint("moduleScores=",moduleScores)
 # 方案不合适返回0,否则返回方案评分
 def moveBlockReference(position):
@@ -81,7 +111,7 @@ def moveBlockReference(position):
   useAreaPositions.clear()
   conf.myprint(conf.moduleLengths)
   currentScore.clear()
-  currentScore.append(position)
+  currentScore.append("".join(position))
   moveResult = 1
   for blockReference in acad.iter_objects("BlockReference"):
     conf.myprint(blockReference.name)
@@ -128,10 +158,7 @@ def moveBlockReferenceWithNewIndex(position,moduleIndex):
   positoins.clear()
   useAreaPositions.clear()
   currentScore.clear()
-  firstScoreItem = []
-  for item in position:
-    firstScoreItem.append(item)
-  firstScoreItem.append(moduleIndex)
+  firstScoreItem = "".join(position)+"_"+ "".join([str(x) for x in moduleIndex])
   currentScore.append(firstScoreItem)
   conf.myprint(conf.moduleLengths)
   blockReferences = []

+ 6 - 2
phxb/utils/main.py

@@ -102,7 +102,12 @@ def createNewFileAndMove(newFil):
 
 def myprocess(m, n):
     positons = getarray.getAllPosition(m, n)
+    i=0
     for positon in positons:
+        if i>10:
+            break
+        else:
+            i=i+1
         # indexAndPositionArray = getarray.getitemIndexAndPositionArray(positons[positon], m, n)
         number = getarray.getitemIndexArrayNumber(positons[positon], m, n)
         if (number == 1):
@@ -118,7 +123,6 @@ def myprocess(m, n):
                     if(not os.path.exists(newFileName)):
                         # copyfile(_rootPath + _originFile, newFileName)
                         moveMultipleTemplate(newFileName,positons[positon],moduleIndex)
-                        # break
                 # break
             else:
                 print(positons[positon],"is not workable !!")
@@ -152,7 +156,7 @@ def moveMultipleTemplate(fileName,position,moduleIndex):
 # openOriginFile()
 # tempStorageModules()
 # print(is_open(_rootPath+_originFile))
-# myprocess(4, 3)
+myprocess(4, 3)
 # openFile(r"F:\autocad_temp\newfile023.dwg")
 # is_open(r"F:\autocad_temp\origin11.dwg")
 # acad = Autocad(create_if_not_exists = False)