duh 6 лет назад
Родитель
Сommit
ba04e45c66
5 измененных файлов с 55 добавлено и 17 удалено
  1. 5 1
      phxb/test.py
  2. 39 6
      phxb/utils/GetAllModule.py
  3. 1 0
      phxb/utils/conf.py
  4. 4 4
      phxb/utils/getarray.py
  5. 6 6
      phxb/utils/main.py

+ 5 - 1
phxb/test.py

@@ -185,7 +185,7 @@ def getModuleMovePath(x10,y10,width1,height1,x1,y1,x20,y20,width2,height2,x2,y2)
 # getMovePath2(800,700,600,400,2000,0,800,900)
 # getMovePath2(800,700,600,400,1000,100,800,900)
 # getMovePath2(800,700,600,400,600,100,800,900)
-getModuleMovePath(800,700,600,400,900,500,1500,1100,400,800,1700,800)
+# getModuleMovePath(800,700,600,400,900,500,1500,1100,400,800,1700,800)
 def testAppend():
     score = []
     for i in range(100):
@@ -193,6 +193,10 @@ def testAppend():
         s.append(i)
         score.append(s)
         print(score)
+def testRange():
+    for i in range(3,10,2):
+        print(i)
+testRange()
 # testAppend()
 
 

+ 39 - 6
phxb/utils/GetAllModule.py

@@ -37,11 +37,44 @@ def printTheTypeObject(type):
   #按类型查找出所有某种图元
   for text in acad.iter_objects(type):
     conf.myprint(text.name)
-def addCurrentScoreToScores():
+# 保存正确方案的分数
+def addCurrentScoreToScores(moveResult):
   temp = []
   for item in currentScore:
     temp.append(item)
-  scores.append(temp)
+  if moveResult > 0:
+    scores.append(temp)
+# 根据scores给方案打分
+def scoreModule():
+  moduleScores = []
+  tempLength = len(scores[0])-1
+  # socres中目前存储  位置、入口雷达半径、入口与模块连线长度、模块间连线长度,入口与模块间撞点,模块与模块间撞点
+  maxs = [0]*tempLength
+  mins = [0]*tempLength
+  detarLength = [0]*tempLength
+  fullSocres = [10,10,10,5,5]
+  fullSocresDirect = [1,-1,-1,-1,-1]
+  # 先获取最大值和最小值
+  for item in scores:
+    for itemIndex in range(tempLength):
+      if item[itemIndex+1]>maxs[itemIndex]:
+        maxs.pop(itemIndex)
+        maxs.insert(itemIndex,item[itemIndex+1])
+      elif 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 = []
+  for item in scores:
+    templateScore.append(item[0])
+    for itemIndex in range(tempLength):
+      if(fullSocresDirect[itemIndex] == 1):
+        templateScore.append((item[itemIndex+1]-mins[itemIndex])*fullSocres[itemIndex]/detarLength[itemIndex])
+      else:
+        templateScore.append(fullSocres[itemIndex] - (item[itemIndex+1]-mins[itemIndex])*fullSocres[itemIndex]/detarLength[itemIndex])
+    moduleScores.append(templateScore)
+  conf.myprint("moduleScores=",moduleScores)
 # 方案不合适返回0,否则返回方案评分
 def moveBlockReference(position):
   positoins.clear()
@@ -60,7 +93,7 @@ def moveBlockReference(position):
         if(result == 0):
           moveResult = result
   conf.myprint("currentScore size =",len(currentScore),",scores size=",len(scores))
-  addCurrentScoreToScores()
+  addCurrentScoreToScores(moveResult)
   conf.myprint("scores=",scores)
   for blockReference in needDeleteBlockReferences:
     blockReference.delete()
@@ -115,7 +148,7 @@ def moveBlockReferenceWithNewIndex(position,moduleIndex):
     if(result == 0):
         moveResult = result
   conf.myprint("currentScore size =",len(currentScore),",scores size=",len(scores))
-  addCurrentScoreToScores()
+  addCurrentScoreToScores(moveResult)
   conf.myprint("scores=",scores)
   for blockReference in needDeleteBlockReferences:
       blockReference.delete()
@@ -151,7 +184,7 @@ def isWorkable(position):
   return 1
 # 获取组件的四点坐标
 def getCenterPoint(wallIndex, x, y, blockIndex):
-  height = conf.moduleLengths[blockIndex];
+  height = conf.moduleLengths[blockIndex]-conf.moduleLengthOffsets[blockIndex];
   width = conf.moduleHeights[blockIndex];
   useHeight = conf.moduleUseLength[blockIndex]
   useWidth = conf.humenLenght
@@ -281,7 +314,7 @@ def getDistince(point1,point2):
   detarY = point1[1]-point2[1]
   return math.sqrt(detarX**2+detarY**2)
 def getDoorBeginPoint():
-  return ((conf.doorAlign[0]+conf.doorLength+conf.doorAlign[1])/2,0)
+  return (conf.doorAlign[0]+conf.doorLength/2,0)
 def drawLines(includePoints):
   lineLength = 0;
   if(len(includePoints)>1):

+ 1 - 0
phxb/utils/conf.py

@@ -7,6 +7,7 @@ roomLengths = (3000,2200)
 # 模块长度
 humenLenght = 650
 moduleLengths = (800,1000,850)
+moduleLengthOffsets = (0,0,200)
 moduleHeights = (1500,550,700)
 moduleUsePoint = [[1050,800],[550,500],[700,450]]
 moduleUseCenterPoint = [[1050,800+humenLenght/2],[550+humenLenght/2,500],[700+humenLenght/2,450]]

+ 4 - 4
phxb/utils/getarray.py

@@ -161,19 +161,19 @@ def getitemIndexAndPositionArray(itemIndex, m, n):
     return a
 #获取单个组合的各边重复项的排列数
 def getitemIndexArrayNumber(itemIndex,m,n):
-    itemIndexArrayNumber = 0;
+    itemIndexArrayNumber = 1;
     a = getitemIndexArray(itemIndex,m,n)
     for item in a:
         intItem = int(a[item])
         if(intItem > 1):
-            itemIndexArrayNumber = jieChenNumber(intItem)+itemIndexArrayNumber
+            itemIndexArrayNumber = jieChenNumber(intItem)*itemIndexArrayNumber
     if(itemIndexArrayNumber == 0):
         itemIndexArrayNumber = 1
     return itemIndexArrayNumber
 # result = changeInt2Str(14,3);
 # conf.myprint(result)
-getAllPosition(3, 3)
-# getAllArrayNumber(4,3)
+# getAllPosition(3, 3)
+# getAllArrayNumber(4,8)
 # getitemIndexArray("11213",5,5)
 # getitemIndexArrayAndIndex("11213",5,5)
 # conf.myprint(getModuleIndex("11212",5,5))

+ 6 - 6
phxb/utils/main.py

@@ -14,8 +14,8 @@ _originFile = "origin.dwg"
 
 templateIndex = {'md_xs','md_py','md_rc'}
 doorName = 'ssdr_800'
-correctFilePath = "newfile2\\"
-errorFilePath = "errorfile2\\"
+correctFilePath = "newfile3\\"
+errorFilePath = "errorfile3\\"
 
 # 这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败
 # print(acad.doc.Name)
@@ -123,7 +123,7 @@ def myprocess(m, n):
             else:
                 print(positons[positon],"is not workable !!")
             # break
-
+    GetAllModule.scoreModule()
 def moveSingleTemplate(fileName,position):
     # openFile(fileName)
     GetAllModule.resetConfUsed()
@@ -152,14 +152,14 @@ 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)
 # acad.prompt("Hello, Autocad from Python\n")
 # print(acad.doc.Name)
-# moveMultipleTemplate(r"F:\autocad_temp\newfile2\newfile.dwg",'222',[1,2,0])
-# moveMultipleTemplate(r"F:\autocad_temp\newfile2\newfile3.dwg",'222',[1,2,0])
+# moveMultipleTemplate(r"F:\autocad_temp\newfile2\newfile.dwg",'001',[0,1,2])
+# moveMultipleTemplate(r"F:\autocad_temp\newfile2\newfile3.dwg",'020',[2,1,0])
 # moveMultipleTemplate(r"F:\autocad_temp\newfile2\newfile4.dwg",'222',[1,2,0])
 # moveMultipleTemplate(r"F:\autocad_temp\newfile2\newfile5.dwg",'110',[1,0,2])
 # moveMultipleTemplate(r"F:\autocad_temp\newfile2\newfile5.dwg",'222',[1,2,0])