×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

TARGETVALUE OPTIMIZATION??

TARGETVALUE OPTIMIZATION??

TARGETVALUE OPTIMIZATION??

(OP)
I'm traing to run an optimization with target value,
but I Have always this error : "the method targetvalue failed"

Does anyone know why?

Dim oActiveDoc As Document
Set oActiveDoc = CATIA.ActiveDocument

' Check whether the document is a CATPart
If (InStr(oActiveDoc.Name, ".CATPart")) <> 0 Then

' Retrieve the collection object which contains
' all the document relations.
' The statements below are only valid when the active
' document is a CATPart
Dim oRelations As Relations
Set oRelations = oActiveDoc.Part.Relations

' Retrieve the collection object which contains
' all the document parameters.
Dim oParameters As Parameters
Set oParameters = oActiveDoc.Part.Parameters

' Create Real type parameter as objective to be optimized.
Dim oFx As Parameter
Set oFx = oParameters.CreateReal("Real1", 199)
oFx.Rename "fx"

' Create Real type parameter as free parameter.
Dim oX As RealParam
Set oX = oParameters.CreateReal("Real2", 299)
oX.Rename "x"

' Create a formula to be optimized.
Dim oFormula As Formula
Set oFormula = oRelations.CreateFormula("Objective", "This is the objective function.", oFx, "x*x + 8.0")

' Retrieve the collection object which contains
' all the document optimizations.
Dim oOptimizations As Optimizations
Set oOptimizations = oRelations.Optimizations

' Create the optimization feature.
Dim oOptimization1 As Object
Set oOptimization1 = oOptimizations.CreateOptimization()
oOptimization1.OptimizationType = catTargetValue
oOptimization1.AlgorithmType = catSimulatedAnnealing


'Set up the optimization feature attributes.
oOptimization1.MaxEvalsNb = 300
oOptimization1.UseMaxTime = True
oOptimization1.MaxTime = 2 '2 minutes.
oOptimization1.UseMaxEvalsWoImprovement = True
oOptimization1.MaxEvalsWoImprovement = 200
Dim otar As RealParam
Set otar = oParameters.CreateReal("tar", 999)
oOptimization1.TargetValue = otar

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources