how to automatically creates a relationship
You would need to write a custom extension or module. 
in this extension or module, implement hook_civicrm_post()...

Drupal module's are the simplest, if you are integrating with Drupal that is

so for example

function MYMODULE_civicrm_post($op, $objectName, $objectId, &amp;$objectRef) {
  // if location type  is Home (location_type_id:1), operation is create, and object type is Address
  if ($op == 'create' &amp;&amp; $objectName == 'Address' &amp;&amp; $objectRef-&gt;location_type_id == 1) {
    // look for other addresses with the same street address, city, state, postal code, zip, and country
    $result = civicrm_api3('Address', 'get', array(
      'sequential' =&gt; 1,
      'street_address' =&gt; $objectRef-&gt;street_address,
      'city' =&gt; $objectRef-&gt;city,
      "state_province_id" =&gt; $objectRef-&gt;state_province_id,
      "postal_code" =&gt;  $objectRef-&gt;postal_code,
      "country_id" =&gt;  $objectRef-&gt;country_id,
      'contact_id' =&gt; array('!=' =&gt; $objectRef-&gt;contact_id),
    ));
    if(!empty($result['count'])) {
      foreach ($result['values'] as $value) {
        // check for existing relationship between contacts
        $result1 = civicrm_api3('Relationship', 'get', array(
          'sequential' =&gt; 1,
          'contact_id_a' =&gt; $value['contact_id'],
          'contact_id_b' =&gt; $objectRef-&gt;contact_id,
          'relationship_type_id' =&gt; 8, // change this to the id of the type of relationship you want to create
        ));
        $result2 = civicrm_api3('Relationship', 'get', array(
          'sequential' =&gt; 1,
          'contact_id_a' =&gt; $objectRef-&gt;contact_id,
          'contact_id_b' =&gt; $value['contact_id'],
          'relationship_type_id' =&gt; 8, // change this to the id of the type of relationship you want to create
        ));

        // if no existing relationship found create the relationship
        if($result1['count'] == 0 &amp;&amp; $result2['count'] == 0) {
          $create_result = civicrm_api3('Relationship', 'create', array(
            'sequential' =&gt; 1,
            'contact_id_a' =&gt; $objectRef-&gt;contact_id,
            'contact_id_b' =&gt; $value['contact_id'],
            'relationship_type_id' =&gt; 8, // change this to the id of the type of relationship you want to create
            'is_active' =&gt; 1,
          ));
        }
      }
    }
  }
}