MetaCase Homepage
Forum Home Forum Home > > MetaEdit+
  New Posts New Posts RSS Feed - Enforce unique combination of parameters
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Enforce unique combination of parameters

 Post Reply Post Reply
Author
Message
edward22243 View Drop Down
Major Contributor
Major Contributor
Avatar

Joined: 19.Apr.2019
Points: 41
Post Options Post Options   Thanks (0) Thanks(0)   Quote edward22243 Quote  Post ReplyReply Direct Link To This Post Topic: Enforce unique combination of parameters
    Posted: 19.Apr.2019 at 13:59
I have an object called Cell, and it represents a physical production cell in a 2D-grid (u,v).
The location are paramters u and v and the combination needs to be unique. What does not work is that I set u and v unique individually. After all (1,0) and (1,1) are diffent locations, but they have a common u, namely u=1, so it is not unique.


I solved this by defining a location as a string '(u,v)'  instead of 2 parameters. 

But I want to know how I can retrieve u and v from the string '(u,v)'  regex (\d+,\d+) 

or go back to two parameters, but add a check for unique of the combi?

Each way is okay for me.

Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 641
Answer Answer
Post Options Post Options   Thanks (0) Thanks(0)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 19.Apr.2019 at 14:21
If you want UI enforcement of global uniqueness (i.e. trying to enter (1,1) a second time anywhere will be prevented), you can mark that property slot in Cell as Unique. If you want UI enforcement of local uniqueness (i.e. trying to add a second Cell with (1,1) to the same graph will be prevented), you can add a Uniqueness Constraint to the Graph type.

In both cases, you can extract the u and v parameters with a regex translator. I'd drop the parentheses, to save the user having to read and type them all the time, and maybe allow whitespace after the comma:
to '%u
/(\d+),\s*\d+/ $$1'
endto

to '%v
/\d+,\s*(\d+)/ $$1'
endto

@u = :Location%u 
@v = :Location%v

'u is ' @u ' and v is ' @v

To make sure the users follow the legal format for Location, you can add a corresponding Regex to the property type, \d+,\s*\d+. (If you want to allow decimals, scientific notation etc., just extend \d as desired.)

If on the other hand you want to keep u and v separate, and it's OK just to show an error / warning in the model if values aren't unique, see 6.7.4 Checking instance uniqueness in the Workbench User Guide. If you define an Identifier Generator for the Cell object type, outputting both u and v (e.g. :u ',' :v), those examples should work as-is.
Back to Top
edward22243 View Drop Down
Major Contributor
Major Contributor
Avatar

Joined: 19.Apr.2019
Points: 41
Post Options Post Options   Thanks (0) Thanks(0)   Quote edward22243 Quote  Post ReplyReply Direct Link To This Post Posted: 19.Apr.2019 at 14:59
Hello Steven,

That worked. Was looking through the documentation for regex but could not really fnd it. 

Had to look for translaters instead, that works good.  
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.05
Copyright ©2001-2022 Web Wiz Ltd.

This page was generated in 0.063 seconds.