我正在测试新的 Parcel 2,所以我做了一个简单的项目来测试它,但是当我尝试将 HTML 文件导入到 Javascript 中时遇到了一个不方便的问题,请参阅下面我在做什么。< /p>
ctypes
#If there is an optimal solution, output the optimal solution and the extreme value of the objective function
X=[0]*self.X_count
count=0
for i in self.B:
X[i]=self.bound[count][self.X_count]
count+=1
Z=0
for i in range(self.X_count):
Z+=self.z[i]*X[i]
if self.special:
print("No feasible solution")
elif self.flag==1:
print("There is a unique optimal solution",X,format(Z,'.2f'))
elif self.flag==0:
print("No solution")
#Check(), check whether it is the optimal solution
def Check(self):
self.flag=1
for i in range(self.b_count):
if self.bound[i][self.X_count]<0: #If there are constraints on the right end of the constant is negative, continue to iterate
self.flag=0
break
#pivot(), basis transformation (rotation)
def pivot(self):
[i,j,main]=self.FindMain() #Simplicity method: Find the main element
self.B[i]=j #The swap-out variable in the base variable is replaced with the swap-in variable
for x in range(self.X_count+1): #Transform the line of the base variable
self.bound[i][x]=self.bound[i][x]/main
for k in range(self.b_count): #Transform other lines
if k!=i:
times=self.bound[k][j] #multiple
for t in range(self.X_count+1):
temp=self.bound[i][t]*times
self.bound[k][t]=self.bound[k][t]-temp
def FindMain(self): #Find the main element according to the θ rule and determine the swap-in and swap-out variables
matbound=np.mat(self.bound)
if np.min(matbound[:,:-1])>=0:
self.special=True
bi=[]
for i in range(self.b_count):
bi.append(self.bound[i][self.X_count])
iout=bi.index(min(bi)) #OK to swap out variables
Theta=[] #θ
for j in range(self.X_count):
if self.bound[iout][j]>=0 or self.C[j]==0: #The dividend is not 0, the divisor must be less than 0
theta=float('inf') #Give a positive infinite number for easy elimination
else:
theta=self.C[j]/self.bound[iout][j]
Theta.append(theta)
jin=Theta.index(min(Theta)) #OK to swap in variables
main=self.bound[iout][jin]
return [iout,jin,main]
{
"name": "client-example",
"version": "0.0.1",
"description": "",
"scripts": {
"build": "parcel build ./src/index.html --dist-dir ./dist",
"dev": "parcel ./src/index.html --dist-dir ./dist-dev",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Varela",
"license": "Apache-2.0",
"devDependencies": {
"@parcel/transformer-inline-string": "^2.0.0-beta.2",
"@parcel/transformer-sass": "^2.0.0-beta.2",
"parcel": "^2.0.0-beta.2"
}
}
npm run dev
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<script src="./main.js"></script>
</body>
</html>
import otherHTML from "./other.html"
软件 | 版本 |
---|---|
包裹 | 2.0.0-beta.2 |
节点 | v14.17.0 |
npm/纱线 | 7.18.1 |
操作系统 | Fedora 34(三十四)x86_64 |