Scripting Optimization - samples

Here are some simple scripts to configure and run the Optimizer from a script.

Editing an existing user-defined script variable (in row #4):

Sub Main
	
	Dim optvar As T_MZRVARIABLE, myScript As String
	GetIthMzrVariable 4, optvar

	myScript = getMyScript()
	optvar.Script = myScript

	SetIthMzrVariable 4, optvar

End Sub


Function getMyScript()
	Dim myScript As String

	'no need for the Sub header and footer. Just need the content.

	myScript = "g_success = False" & vbCrLf
	myScript &=	"If IsLens(g_entity) Then" & vbCrLf
	myScript &= "End If"

	getMyScript = myScript
End Function

Editing an existing user-defined script aberration (in row #1):

Sub Main
	
	Dim optab As T_MZRABERRATION, myScript As String
	GetIthMzrAberration 1, optab

	myScript = getMyScript()
	optab.Script = myScript

	SetIthMzrAberration 1, optab

End Sub


Function getMyScript()
	Dim myScript As String

	'no need for the Sub header and footer. Just need the content.

	myScript = "g_success = False" & vbCrLf
	myScript &=	"If IsLens(g_entity) Then" & vbCrLf
	myScript &= "End Iff"

	getMyScript = myScript
End Function

Configuring and running the optimizer:

Sub Main
	
	'set method
	SetMzrMethod "Simplex"

	'set max num of iterations
	SetMzrStopOnIterCount True
	SetMzrStopOnIterCountValue 100

	'switch off all other stopping criteria
	SetMzrStopVarChange False
	SetMzrStopMeritFunctionChange False
	SetMzrStopMeritFuncThreshold False

	'draw to 3D View
	SetMzrRedraw3DView True
	SetMzrRedraw3DViewCount 1

	'run
	Optimize()

End Sub

Still need help? Contact Us Contact Us